Hi all,
i've done other little steps forward on my stupid game. Now i've change the key reading part using SetWindowsHookEx, to make it compatible in NT and faster.
Unfortunately, now the starship movements is much more slower.
So i probably should have to come back to In instruction.
Any help appreciated.
i've done other little steps forward on my stupid game. Now i've change the key reading part using SetWindowsHookEx, to make it compatible in NT and faster.
Unfortunately, now the starship movements is much more slower.
So i probably should have to come back to In instruction.
Any help appreciated.
It indeed runs on win2k now, but as you said the movement is really slow.
The problem here is that when you keep a key pressed, the same happens as in a text editor, first one character is shown, then there's a little pause and then the character is repeated at a fixed rate.. So the speed of the response to keypresses depends on the keyboard settings.
If possible, I would use the alternative of continious polling for pressed keys, at a fixed rate based on a timer so that the speed is the same on all computers.
Thomas
The problem here is that when you keep a key pressed, the same happens as in a text editor, first one character is shown, then there's a little pause and then the character is repeated at a fixed rate.. So the speed of the response to keypresses depends on the keyboard settings.
If possible, I would use the alternative of continious polling for pressed keys, at a fixed rate based on a timer so that the speed is the same on all computers.
Thomas
I don't know if you've already thought of this, or if there is a reason it wont work for you, but what about GetAsyncKeyState? That's the one I always use in C if I'm not using DirectInput and it's responsive enough for me. Hope it helps, good luck :alright:
Why don't you do a Peekmessage once every frame with the WM_KEYFIRST and WM_KEYLAST constants so that keyboard message are filtered through.
Eoine,
i've try to filter this messages in the WindProc.
Nothing change. Control remain slow.
AlexEiffel,
Your seems the easy and best way.
I've change the code as follow:
But if want get any key ?
thanks all againg for yuor experience.
i've try to filter this messages in the WindProc.
Nothing change. Control remain slow.
AlexEiffel,
Your seems the easy and best way.
I've change the code as follow:
call GetAsyncKeyState, 25h
cmp ax,8000h
je @Left
call GetAsyncKeyState, 27h
cmp ax,8000h
je @Right
call GetAsyncKeyState, 28h
cmp ax,8000h
je @Down
call GetAsyncKeyState, 26h
cmp ax,8000h
je @Up
But if want get any key ?
thanks all againg for yuor experience.
GetAsyncKeyState will work for any key. I do have a suggestion for you though. Instead of....
call GetAsyncKeyState, 25h
cmp ax,8000h
try...
call GetAsyncKeyState, VK_LEFT
cmp ax,8000h
It will make your code easier to read if you use the Virtual Key codes. You can find a list of them all in the Windows Help. Again, I haven't tried this in asm, but I don't see why it wouldn't work. You can call GetAsyncKeyState anywhere in your code, so you don't have to rely and wait on the message loop. Happy coding
:alright:
call GetAsyncKeyState, 25h
cmp ax,8000h
try...
call GetAsyncKeyState, VK_LEFT
cmp ax,8000h
It will make your code easier to read if you use the Virtual Key codes. You can find a list of them all in the Windows Help. Again, I haven't tried this in asm, but I don't see why it wouldn't work. You can call GetAsyncKeyState anywhere in your code, so you don't have to rely and wait on the message loop. Happy coding
:alright:
GetAsyncKeyState is very powerful.
It remain a problem: the start screen of my game says:
Press Any Key To start ....
How can i do with GetAsyncKeyState ? Have i to use the WM_KeyDown Msg for this ?
Thanks again
It remain a problem: the start screen of my game says:
Press Any Key To start ....
How can i do with GetAsyncKeyState ? Have i to use the WM_KeyDown Msg for this ?
Thanks again
That sounds like a good idea. Since it's just the start button, the responsiveness of the message proc doesn't really matter.
Try this method :
Use a dword to keep the state of the keys pressed by the player. When a key is pressed, set a bit to 1 in the dword. Use a different bit for each key. When the key is released, set the bit to 0. On every timer ticks, scan the dword and move the player when a bit is set.
In pseudo code :
Use a dword to keep the state of the keys pressed by the player. When a key is pressed, set a bit to 1 in the dword. Use a different bit for each key. When the key is released, set the bit to 0. On every timer ticks, scan the dword and move the player when a bit is set.
In pseudo code :
; key pressed
keyPressed DWORD 0
; key bit
LEFT_KEY = 1
RIGHT_KEY = 2
UP_KEY = 4
DOWN_KEY = 8
; when a key is pressed, set the bit to 1
.IF (key == LEFT)
or keyPressed, LEFT_KEY
.ELSE IF (key == RIGHT)
or keyPressed, RIGHT_KEY
; etc
.ENDIF
; when a key is release, set the bit to 0
.IF (key == LEFT)
and keyPressed, (NOT LEFT_KEY)
.ELSE IF (key == RIGHT)
and keyPressed, (NOT RIGHT_KEY)
; etc
.ENDIF
; in the timer message
.IF (key & LEFT_KEY)
; move left
.ENDIF
.IF (key & RIGHT_KEY)
; move right
.ENDIF
; etc
dr.manhattan,
thanks for the method suggested. I will sure try it.
I've implemented GetTickCount as suggested by japheth, to multiply all the movements for the cycle time variable.
Remains two problems: when i move the mouse it break the game for a moment. How can i avoid this ?
How can i perform a movement in diagonal ? It seems the method of dr. Manhattan leve the starship move also in digonal, is It ?
thanks for the method suggested. I will sure try it.
I've implemented GetTickCount as suggested by japheth, to multiply all the movements for the cycle time variable.
Remains two problems: when i move the mouse it break the game for a moment. How can i avoid this ?
How can i perform a movement in diagonal ? It seems the method of dr. Manhattan leve the starship move also in digonal, is It ?
Yes you can move in diagonal. You can also move and shot at the same time.
THANKS ! I IMPLEMENTING IT IMMEDIATLY !! :) :)
What about using VM_KEYDOWN and VM_KEYUP, and store keystate
in a 128byte array? This has worked pretty well for me, and I don't
remember any delays or repeat-delays?
in a 128byte array? This has worked pretty well for me, and I don't
remember any delays or repeat-delays?