www.digitalmars.com         C & C++   DMDScript  

c++ - kbhit() problem...

reply jdave att.net writes:
I'm trying to create a quick c++ console application under WinXP and it appears
that kbhit() doesn't respond to F1-F12 keypresses.   It returns TRUE for other
keypresses, but not the Fns.   Is this the way it's supposed to work?

Thanks,  Jack.
Mar 16 2006
next sibling parent reply Bertel Brander <bertel post4.tele.dk> writes:
jdave att.net wrote:
 I'm trying to create a quick c++ console application under WinXP and it appears
 that kbhit() doesn't respond to F1-F12 keypresses.   It returns TRUE for other
 keypresses, but not the Fns.   Is this the way it's supposed to work?

I don't know how it is supposed to work, but it acts the same way here. You can create your own: #include <windows.h> HANDLE StdIn = GetStdHandle(STD_INPUT_HANDLE); bool KeyHit() { DWORD NumEvents, NumEventsRead; INPUT_RECORD *InputRecord; DWORD i; GetNumberOfConsoleInputEvents(StdIn, &NumEvents); InputRecord = (INPUT_RECORD *)malloc(sizeof(INPUT_RECORD)*NumEvents); PeekConsoleInput(StdIn, InputRecord, NumEvents, &NumEventsRead); for(i = 0; i < NumEventsRead; i++) { if(InputRecord[i].EventType & KEY_EVENT && InputRecord[i].Event.KeyEvent.bKeyDown) { if(InputRecord[i].Event.KeyEvent.wVirtualKeyCode != VK_CONTROL && InputRecord[i].Event.KeyEvent.wVirtualKeyCode != VK_MENU && InputRecord[i].Event.KeyEvent.wVirtualKeyCode != VK_SHIFT) { free(InputRecord); return true; } } } free(InputRecord); return false; } int main() { while(!KeyHit()) ; } -- Absolutely not the best homepage on the net: http://home20.inet.tele.dk/midgaard But it's mine - Bertel
Mar 16 2006
parent jdave att.net writes:
Bertel:   Thanks a million.   That's very helpful.   I appreciate you taking the
time to educate me.     --Jack.



In article <dvcu14$26ji$1 digitaldaemon.com>, Bertel Brander says...
jdave att.net wrote:
 I'm trying to create a quick c++ console application under WinXP and it appears
 that kbhit() doesn't respond to F1-F12 keypresses.   It returns TRUE for other
 keypresses, but not the Fns.   Is this the way it's supposed to work?

I don't know how it is supposed to work, but it acts the same way here. You can create your own: #include <windows.h> HANDLE StdIn = GetStdHandle(STD_INPUT_HANDLE); bool KeyHit() { DWORD NumEvents, NumEventsRead; INPUT_RECORD *InputRecord; DWORD i; GetNumberOfConsoleInputEvents(StdIn, &NumEvents); InputRecord = (INPUT_RECORD *)malloc(sizeof(INPUT_RECORD)*NumEvents); PeekConsoleInput(StdIn, InputRecord, NumEvents, &NumEventsRead); for(i = 0; i < NumEventsRead; i++) { if(InputRecord[i].EventType & KEY_EVENT && InputRecord[i].Event.KeyEvent.bKeyDown) { if(InputRecord[i].Event.KeyEvent.wVirtualKeyCode != VK_CONTROL && InputRecord[i].Event.KeyEvent.wVirtualKeyCode != VK_MENU && InputRecord[i].Event.KeyEvent.wVirtualKeyCode != VK_SHIFT) { free(InputRecord); return true; } } } free(InputRecord); return false; } int main() { while(!KeyHit()) ; } -- Absolutely not the best homepage on the net: http://home20.inet.tele.dk/midgaard But it's mine - Bertel

Mar 17 2006
prev sibling parent "Walter Bright" <newshound digitalmars.com> writes:
<jdave att.net> wrote in message news:dvc9vt$148v$1 digitaldaemon.com...
 I'm trying to create a quick c++ console application under WinXP and it 
 appears
 that kbhit() doesn't respond to F1-F12 keypresses.   It returns TRUE for 
 other
 keypresses, but not the Fns.   Is this the way it's supposed to work?

You can download the source to microemacs from www.digitalmars.com, and see how it (successfully) handles the keyboard.
Mar 18 2006