Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 16, 2006 kbhit() problem... | ||||
---|---|---|---|---|
| ||||
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. |
March 16, 2006 Re: kbhit() problem... | ||||
---|---|---|---|---|
| ||||
Posted in reply to jdave | 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 |
March 17, 2006 Re: kbhit() problem... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bertel Brander | 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 |
March 18, 2006 Re: kbhit() problem... | ||||
---|---|---|---|---|
| ||||
Posted in reply to jdave | <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. |
Copyright © 1999-2021 by the D Language Foundation