Hello,
I have been looking for controling codes of buttons in c. For example how can I make my program do a specific action when I press b ? Or how can I make my program press b by itsself? . Any source code would be appreciated.
Thank you.
Hello,
I have been looking for controling codes of buttons in c. For example how can I make my program do a specific action when I press b ? Or how can I make my program press b by itsself? . Any source code would be appreciated.
Thank you.
Under which circumstances? In Windows, Linux, Dos, OS/2 ... ?
In Windows, you can certainly make an application think you pressed a key on the keyboard [buttons, I think of buttons in dialog boxes or like the Submit Reply button when I'm replying to a post, rather than keys on the keyboard]
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I have meant the keys on the keybord. For example how can I make my program exit when I press q ? But I dont want to press enter after I press q. I want it to exit just after I press the q button on the keybord.
Windows or Linux (or other OS?)
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
windows.
I copied this from somewhere:
If you still want to see what you are typing, but want the application to immediately get the input, remove the "ENABLE_ECHO_INPUT" from the above.Code:DWORD origKBMode; void SetKbdModeRaw(void) { DWORD mode; GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &mode); if (origKBMode == 0) origKBMode = mode; mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT); SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), mode); } void RestoreKbdMode(void) { SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), origKBMode); }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I am sorry I did unterstand codes slightly , but I couldnt understand how I can use it. Sorry for my lack of experience.
Well, you don't really need to UNDERSTAND how it works. [I don't quite know what's happening INSIDE the calls either - I have a fair idea, but that's about it]
The code I gave will basicly set the standard input so that it's "raw", which means that the input is not processed and held until you press enter. Instead, each keypress is sent directly to the application when it's made.
I missed out the include:
You then just call SetKbdModeRaw() at start of your program, and read the keyboard one key at a time, using for example getch().Code:#include <windows.h>
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Wow, I got what you said, but I saw that getch() funct. for the first time. And interestingly , I dont need to call SetKbdModeRaw() if I use getch(). getch() already does what I want. But why ? nOW ı am confused . =)
I recommend a visit to the FAQ.
ukkeyy. Thanks.