Skip to main content
gamedev.net
🔒 Locked

Checking the input buffer

Started by zackriggle 2 replies 400+ views
Original Post
zackriggle
zackriggle
Is there a way to determine if the shift or ctrl keys were pushed in unison (at the same time as 4 some dummies) with another key. I know i have to use dwControlKeyState (INPUT_RECORD::Event::KeyEvent::dwControlKeyState). There is nothing at MSDN on this, other than the following:
-----------------------------------------------------------------
dwControlKeyState:
State of the control keys. This member can be one or more of the following values. Value Meaning 
CAPSLOCK_ON           The CAPS LOCK light is on. 
ENHANCED_KEY          The key is enhanced. 
LEFT_ALT_PRESSED      The left ALT key is pressed. 
LEFT_CTRL_PRESSED     The left CTRL key is pressed. 
NUMLOCK_ON            The NUM LOCK light is on. 
RIGHT_ALT_PRESSED     The right ALT key is pressed. 
RIGHT_CTRL_PRESSED    The right CTRL key is pressed. 
SCROLLLOCK_ON         The SCROLL LOCK light is on. 
SHIFT_PRESSED         The SHIFT key is pressed. 
-----------------------------------------------------------------
 
Help asap! Why don't we just kill the guys who write error messages. It'd make our lives a hell of a lot easier **************************** Gimme a break, I'm Just 13 (14 in JULY) [edited by - zackriggle on June 12, 2002 8:39:00 PM] [edited by - zackriggle on June 12, 2002 8:39:29 PM]
Spartacus
Spartacus
Hmm...that''s strange. This is a question I have never seen asked before, and just as im going to ask the question myself, someone else does it . Im using a console with ReadConsoleInput, but I can''t figure out how to check if the return key has been pressed. Comparing wVirtualKeyCode to VK_RETURN does not work. Does someone know how to do this?
Real programmers don't document, if it was hard to write it should be hard to understand
zackriggle
zackriggle
I think i know what you mean (and i think you mean how to check to see if ENTER was pressed *BY* *ITSELF*)

Since I have one handy, and don't want to pick it apart, im gonna post a function that will return and int (you can check to see what it is by #defines). You can check to see if almost any key is pressed.


    
#ifndef ZACHS_GET_ENTER_PRESS
#define ZACHS_GET_ENTER_PRESS
#define KEYPRESSED iRecord.Event.KeyEvent.wVirtualKeyCode
void GetEnter()
{
HANDLE hInput;
INPUT_RECORD iRecord;
DWORD dwEvents;

hInput = GetStdHandle(STD_INPUT_HANDLE);
dwEvents = 0;


sleep(100); /* This is to catch any accidental keypresses. This isn't "needed" but is very useful if the user pressed enter any time directly before you call this function */
while(1)
{
// Put some code here (like printing "Press ENTER to continue...

FlushConsoleInputBuffer(hInput);
ReadConsoleInput(hInput, &iRecord, 1, &dwEvents);
if(KEYPRESSED = VK_RETURN)
break;
}
}
#endif


BTW, I am working on my own, complete IO header files. Right now I am working on an enhanced equivalent of cin.getline. All original cin functions were completely and utterly disabled if you ENABLED_PROCESSED_INPUT on you standard input (which is the exact reason i am writing my own . I also have my own menu system thingy which gets an interger value for the choice, and cancels if the user presses Escape, or if the first digit is 0 (zero). Even if enter a large number, then backspace a bunch of times and press 0, it will still cancel (and thus return 0).
As of yet, i have not started on my output header file (as I do not have a reason to do so. I expect to be done by the end of next week (i'm goin to my cuz's house and it's gonna be hard to find time to code in between playing Grand Theft Auto 3 on PS2 and going to the bathroom

[edited by - zackriggle on June 12, 2002 8:36:52 PM]

[edited by - zackriggle on June 12, 2002 8:38:21 PM]
Spartacus
Spartacus
Thanks for the help Zackriggle...I got everything working fine now ...

To check if for example ctrl has been pressed down in unison with another key I think you have to use the field wVirtualKeyCode. Compare this field to VK_CONTROL to check whether the control key has been pressed. Now, if you want to check if the control key is pressed at the same time as for example the ''A'' key, you could do something like this:


KEY_EVENT_RECORD input;
if(input.wVirtualKeyCode & VK_RETURN)
{
if(input.uChar.AsciiChar == ''A'')
return CTRL_WAS_PRESSED_AT_THE_SAME_TIME_AS_A; //
}


At least that''s what I think you could do. I have not tried it out yet, but I think it will work.

René
Real programmers don't document, if it was hard to write it should be hard to understand

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.