Skip to main content
gamedev.net
🔒 Locked

[.net] Keyboard input help

Started by generic_name 3 replies 1k views
Original Post
generic_name
generic_name
What can I use for keyboard input besides _KeyDown and DX? I'd like to stay away from DirectInput because of possible problems compiling on the computers at school.
Geronimo2000
Geronimo2000
I'm not sure if I fully understand the context for your question, but have you looked at setting up event handlers for .NET controls which trigger when a key is pressed? You could also derive from a .NET control and override OnKeyPress functions.
generic_name
generic_name
This is for a game and I was wanting something like GetAsyncKeyState() where there is no delay.
vermilion_wizard
vermilion_wizard
You could just P/Invoke to GetAsyncKeyState if you want: http://www.pinvoke.net/default.aspx/user32/GetAsyncKeyState.html
That would break your portability to Linux if you cared about that though.

The other approach would be to write a little class which keeps an array for the various keys, then attaches to your Form's KeyDown and KeyUp events (make sure KeyPreview is true) and keeps track of which keys are up and down.
generic_name
generic_name
Quote:
Original post by kanato
You could just P/Invoke to GetAsyncKeyState if you want: http://www.pinvoke.net/default.aspx/user32/GetAsyncKeyState.html
That would break your portability to Linux if you cared about that though.

The other approach would be to write a little class which keeps an array for the various keys, then attaches to your Form's KeyDown and KeyUp events (make sure KeyPreview is true) and keeps track of which keys are up and down.


I tried importing GetAsyncKeyState and it worked but if you pressed one key and then another it didn't seem to behave properly.

What I did find out though is if you just have Microsoft.DirectX.DirectInput.dll in the folder the game is ran I can use DirectInput and DX doesn't have to be installed on the computer.

Actually, I did it a different way then in that link. That way would probably work but DirectInput is quite simple to use in C#.

Topic Locked

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

Sign in to reply to this topic.