Re: [GD-Windows] GetAsyncKeyState / DI
Brought to you by:
vexxed72
From: <cas...@ya...> - 2002-11-05 22:31:04
|
The thing I don't like about GetAsyncKeyState is that you can loose keys pressed between frames. It also doesn't give you information about when a key has been pressed or released. However, testing keys by polling is usually cleaner and easier than sending and processing events. Instead of that I use a different polling mechanism. I associate three different flags to each key: enum { KEY_OFF = 0x00, KEY_ON = 0x01, KEY_BEGIN = 0x02, KEY_END = 0x04 }; And test them like this: if( GetKey( KEY_SPACE ) ) fire(); if( GetKey( KEY_CONSOLE )&KEY_BEGIN ) console.toggle(); if( GetKey( KEY_ESCAPE )&KEY_END ) exit(); When a key down is received I set the key state to KEY_BEGIN|KEY_ON, and when key up, I toggle the the KEY_END flag. On every frame I update the key states like this: for each key { if( Key[i].state&KEY_BEGIN ) Key[i].state ^= KEY_BEGIN; if( Key[i].state&KEY_END ) Key[i].state = KEY_OFF; } So, it's possible to recieve up and down messages in the same frame without loosing the key pulsation. You can put that on top of any input mechanism, WM_KEY events, direct input buffers, SDL keyboard events, etc. Whatever you feel more confortable with. Actually all that is mixed with my action mapping code, so instead of testing for keys I test for actions, and that makes the whole thing much more intuitive. Ignacio Castaño cas...@ya... Pierre Terdiman wrote: > > DI can give you buffered input, which has it's benefits. > > What is it, exactly ? Do you mean it records (say) pressed keys in the > background, maybe in another thread, and gives all pressed keys since last > query ? Actually it would be a very good reason to switch to DI. > > >Are you really adverse to using it .... > > No, I was just wondering if it was worth it. Nothing against the idea. > > Pierre _______________________________________________________________ Copa del Mundo de la FIFA 2002 El único lugar de Internet con vídeos de los 64 partidos. ¡Apúntante ya! en http://fifaworldcup.yahoo.com/fc/es/ |