Click to See Complete Forum and Search --> : Input system
vbZombie
Mar 6th, 2001, 12:58 PM
I'm doing an input system to my game with DX8. I use DInput to check if a key has been pressed:
If data(xi).lOfs And data(xi).lData = bDown Then
g_TypedLetter = data(xi).lOfs
End If
Then my app checks what key was pressed:
Select Case g_TypedLetter
Case DIK_A
newChar = "a"
Case DIK_B
newChar = "b"
Case DIK_C
newChar = "c"
Case DIK_D
newChar = "d"
etc..
How can be the conversion from long -> string be optimized?
And how should be shift+alt keys handled? I can already do uppercase letters with caps lock and both shift buttons, but how to get other symbols (e.g. "(", "{") out of the keyboard?
Sastraxi
Mar 7th, 2001, 06:46 PM
I've got an idea... use DInput ONLY for joysticks...
Use Native VB, it's way easier. I'm not saying that it's the best way to go, though. I've never used DInput, but by your code it looks tough.
vbZombie
Mar 8th, 2001, 09:39 AM
One of the main points in my current project is to avoid using native VB (Form_Keydown and alike) because I want to port it to C++ after I've studied it enough. So are there any API calls that return the ASCII value of a keypress (that also knows how a keyboard is mapped)?
HarryW
Mar 8th, 2001, 09:50 AM
You can use GetAsynchKeyState To find out if a particular key has been pressed. It's a Windows API call, so it works in C/C++.
vbZombie
Mar 8th, 2001, 11:17 AM
Hmm.. I'd like to use something like GetKeyboardState (which returns a 256-byte array) but it doesn't have keyUp-keyDown-things. How should AsyncKeyState be used that it would also return everything in one package?
HarryW
Mar 8th, 2001, 12:14 PM
You don't, you just loop. If you consider how this is working at machine code level, something like GetKeyboardState is going to have to loop through the virtual key codes and assign values to the array it returns. Doing this yourself ought to result in a fairly minimal performance loss, perhaps it would even be quicker if you were only checking some keys (ie. the control keys for your game).
GetAsynchKeyState will tell you whether the key is down, and also whether it was pressed the last time you checked, so you can tell whether it's been pressed or released, or is just still pressed down since the last time it was pressed.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.