Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:42:34+00:00 2026-05-26T19:42:34+00:00

I am trying to write a C program which is aware of the control

  • 0

I am trying to write a C program which is aware of the control / alt / shift key being pressed down. I found something that provides this functionality in Java, but that’s not helping me too much.

void CMousepresentView::OnDraw(CDC* pDC)
{
int shiftValue=::GetKeyState(VK_SHIFT);
if(!shiftValue)
pDC->TextOut(0,50,"Shift not pressed");
else
pDC->TextOut(0,50,"Shift pressed");

int ctrlValue=::GetKeyState(VK_CONTROL);
if(!ctrlValue)
pDC->TextOut(0,100,"Ctrl not pressed");
else
pDC->TextOut(0,100,"Ctrl pressed");
}

So what I have so far is quite rudimentary but I must start somewhere. It doesn’t work though, at all.

#include <stdio.h>
#include <ctype.h>

int main(void)
{
  char ch;

  do {
    ch = getchar();
    putchar(ch);
  } while(iscntrl(ch));
  return 0;
}

I was hoping that iscntrl would at least give me some reaction from the system to start debugging and identifying the control sequence keypresses. No such luck.

If I could see an example that outputs “control is pressed / control is released”, I could probably figure out the rest.

Update:
Have had some progress with this http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/

Update:

I think the answer is in using xlib. Thanks everyone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:42:34+00:00Added an answer on May 26, 2026 at 7:42 pm

    You can not check for the silent keys in a console program, not just those keys. If using something like ncurses you might get them as modifiers on other keys.

    If you want to make a program with a graphical user interface, it’s not a problem. Qt is a popular framework for that. Check the documentation for the framework you select.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a c++ program that would read key frames from
I'm trying to write a program that creates a 2D grid in which the
I am trying to write a program in PHP which I had already written
I'm trying to write a simple program in VC++ which will just initialize the
I'm trying to write a program that uses sockets to connect with other instances
I'm trying to write a program in C (on Linux) that loops until the
I'm trying to write a program that reads text from external file (string string
I am trying to write a program that allows a binary to be run,
I am trying to write a program that displays the integers between 1 and
I'm trying to write a program with a function which returns a matrix with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.