www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - kbhit() problem...

↑ ↓ ← 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
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
↑ ↓ → 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
→ "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