Advertisement

Reading keys in Windows

Started by January 07, 2001 10:37 AM
4 comments, last by Sludge 24 years ago
Another Win32 Question again: Is there a function to read keys (like getch()) in the Win32 API? Getch doesn''t seem to work, and the WM_ONKEY message doesn''t work when in DirectDraw full-screen mode. Sludge Software www.sludgesoft.com Developing a secret of mana style role-playing-game
Sludge Softwarewww.sludgesoft.comDeveloping a secret of mana style role-playing-game
well, you have two options. One is to use GetAsyncKeyState(), the other is to use DirectInput.

To use GetAsyncKeyState(), use these macros:
#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) 

then use it like this:
if (KEYDOWN(VK_RETURN)){  ...do stuff...} 


Alternatively, you can learn DirectInput, which really is not hard to learn at all when it comes to keyboard input.


==============================
"Need more eeenput..."
- #5, "Short Circuit"
Blade Edge Software
==============================

Drew Sikora
Executive Producer
GameDev.net

Advertisement
Thanks.

And yes, I already know how to use DirectInput, I just wanted to know how to do it without it

Sludge Software
www.sludgesoft.com
Developing a secret of mana style role-playing-game

Sludge Softwarewww.sludgesoft.comDeveloping a secret of mana style role-playing-game
heh,

i use WM''s and store all of the keystrokes between frames in a LL to be executed each frame.

that way,i don''t lose a keystroke if they -happen- to hit it between frames, and i know what order they hit them in.

put a nice c++ wrapper on it if u wanna crack at it

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have no name that you may call me. I am merely Succinct.
~Succinct Demos Online~

"Hey, where''d that display list rotate off to now?"
-(Drop me a line here)-

-- Succinct(Don't listen to me)
Is there anything inherently wrong with GetKeyboardState?
GetKeyboardState relies on windows messages. That''s a bad thing because if the user presses many keys at once, that means that many messages will be sent, thus slowing your app down.

At least, that''s what I think is the reason why a program I wrote slowed and sputtered when more than 5 keys were pressed.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.

This topic is closed to new replies.

Advertisement