i asked for an alternative to getasynckeystate / getkeystate based on my attempted examples not for more questions on why i dont want to use getasynckeystate. |
*shrug* Fine.
I thought if I could solve your problem with GetAsyncKeyState, you would not have to search for an alternative. But apparently you're not interested.
I can't imagine any other WinAPI call is going to get around whatever problem you're having with GetAsyncKeyState (since they're all going to work the same way)... and since you won't tell me what's broken, it is difficult for me to recommend something I know will work for you. So all I can do it mindlessly list alternative methods of keyboard input and let you drudge through them all.
So here you go. Here's a couple ways I know of:
- WinAPI: GetKeyboardState
- WinAPI: Look for and handle WM_KEYDOWN and WM_KEYUP messages
- XInput: XInputGetKeyStroke
- DirectInput (old): CreateDevice (to create the keyboard object), then GetDeviceState (to get the state of the keys)
- 3rd party libs like SDL/SFML/wxWidgets/Qt/Allegro/FLTK
- conio.h: kbhit and getch
hi, <0 simply states if it is an active key. what you wrote is simply not required. |
I suppose you're right... either will work since if the high bit is set, the resulting number will also be negative.
Though personally I find the & 0x8000 approach to be more explicit and easier to understand (since it's actually checking the desired bit... rather than assuming the desired bit causes the sign of the returned value to change).
But whatever floats your boat.