Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect one or combination of strokes of keys in C?

Tags:

c

c89

How can I detect one or combination of strokes of keys in ANSI C and/or with Win32 SDK?

For example: how can I detect CTRL+ALT+DEL was pressed?

Please provide me with some source code or any web-link.

Please note that, I am using polling mechanism, not event.

I need to do it in win32 console mode.

like image 236
user366312 Avatar asked Nov 15 '22 09:11

user366312


1 Answers

With ANSI C it is impossible, since ANSI C doesn't define any method to access the keyboard in this manner. The lowest-level function in it that takes input from the user is getc that returns a character after it has been entered into stdin and ENTER has been pressed.

As for the Win32 API, indeed this can be done. In the message handling function (WndProc)you should watch for WM_CHAR messages. Modifiers will help you see if CTRL and SHIFT are pressed.


P.S. just a thought, maybe what you're looking for is a tool like Autohotkey?

like image 144
Eli Bendersky Avatar answered Dec 15 '22 13:12

Eli Bendersky