Hi there,
I'm trying to make something move with the keyboard but i can't get that OnKeyDown to work. I tried to put the function to move on the OnKeyDown of teh form but it doesn't execute at all.
> I tried to put the function to move on the OnKeyDown of teh form but it doesn't execute at all.
The OnKeyDown event of the form will only fire if there is no other component on the form that has focus. If there is another component that has focus, the OnKeyDown event of that component fires, not the OnKeyDown event of the form. I suspect that this is what is happening.
thanks for your response
I'm trying to make a little game whit an image in background so how can I catch the keyboard or remove the focus thing on my object
If you want to make a game, you must use a loop where you can call the win api function GetAsyncKeyState.
Or you can use a timer to call GetAsyncKeyState.
The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
SHORT GetAsyncKeyState(
int vKey // virtual-key code
);
VK_LEFT 25 LEFT ARROW key
VK_UP 26 UP ARROW key
VK_RIGHT 27 RIGHT ARROW key
VK_DOWN 28 DOWN ARROW key
Thank you guyz now it worked with the keypreview. But now ihave a problem : the game slow down when i keep the button pressed. I have a background that is running with a timer to move it. I don<t if the thing you speaking of (ICounter) can remove that.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.