Keycode conundrum *SOLVED*

Started by YOke, Mon 29/11/2004 21:14:23

Previous topic - Next topic

YOke

OK... Here's my problem:Ã,  :-\

I'm currently making the fighting engine for FoY. I want the character to only throw one punch for each time I press down a key. Without any code to check this he will repeatedly punch as long as you hold down the key. The way I've solved this is to make so that when the key is pressed the character throws a punch, a variable is set to 1. As long as the variable is 1 he can't throw another punch. I then check to se if the key is not longer pressed and set the variable back to 0 if that is the case.
So far so good.Ã,  8)
My problem is that I want to use the numpad for the fighting controls, and when I assign the right keycodes to the punches, weird shit starts happening! When I now press a key on the numpad assigned to punch he punches repeatedly. I use the numpad with NumLock on so that I am really sending the numbers 1 to 9. They have the same keycode as the "regular" numbers along the top of the keyboard. In fact, when I press 9 on the "regular" keys it works fine and the punch is thrown once. If I press 9 on the numpad the punch is thrown repeatedly until the key is released!Ã,  :-X
The only thing I can explain this with is that a key pressed on the numpad is sent as a pulse instead of a constant signal. I remember from the old DOS days that some keys have double keycodes. This could explain why the program acts the way it does, since pressing the key would make the keyboard send two alternating 8-bit values.Ã,  If this is the case, could somebody help me find out what that second keycode is. If not, any other good ideas?Ã,  ???
And before any of you point out the obvious, yes I'll move the controls over to the keyboard for now.Ã,  ::)

Enlightenment is not something you earn, it's something you pay for the rest of your life.

Ashen

#1
According to the ASCII code references in the manual, and my keyboard:
Numpad 1 = End =Ã,  379
Numpad 3 = Pg Dn =Ã,  381
NumPad 7 = Home = 371
Numpad 9 = Pg Up = 373

Any good?

EDIT:
Also (maybe):
2 = Down arrow, 4 = Left arrow, 6 = Right arrow and 8 = Up arrow. 5 stays the same, apparently.
I know what you're thinking ... Don't think that.

YOke

The thing is that I'm using Left and Right arrows to move the character. If I use the numpad without NumLock on 4 and 6 are left and right arrows. I need all 9 digits for the controls, and therefore have to use the numpad with NumLock on so that the keys are 1 to 9.

Enlightenment is not something you earn, it's something you pay for the rest of your life.

Pumaman

Are you using IsKeyPressed to determine when to set the variable back to 0? If so, it's possible that the different keycodes aren't quite matching up properly in IsKeyPressed and on_key_press.

Can you post the script for checking the key presses and releases?

YOke

#4
I am indeed using IsKeyPressed.

This is for checking the release of a key.
Code: ags

if ((IsKeyPressed(lastkeypressed) != 1) && (iskeyreleased == 1))
	{
	Ã,  iskeyreleased = 0;
	Ã,  lastkeypressed = 0;
	Ã,  SetGlobalInt(66, 0);
	}


What happens elsewhere is simply to check that iskeyreleased is 0 to run the script and set it to 1 when the script has run. As I said, it works fine on letters and even on the other set of numbers.

EDIT: Checked it now, and IsKeyPressed does indeed pass the same numbers with numlock on or off. Problem solved for now! :)

Enlightenment is not something you earn, it's something you pay for the rest of your life.

Ashen

#5
Well, the reason I said those, is -Ã,  with or without NumLock on, my numeric pad always passes as those keys, rather than numbers.

Obviously, it's not worth worrying about if it's only me (or a version issue?), but it seems a shame to get it working as you want it, only to find it doesn't work for other people anyway.

EDIT: Wait, I'm confused here. I was actually making sense? Good God, how did that happen? I barely understood this post.
I know what you're thinking ... Don't think that.

YOke

hehe...

The thing is that with numlock on, the on_key_pressed function returns the value of the numbers (48-57) but the IsKeyPressed returns the same codes as if numlock was off. So I had to check for one code to see if it was pressed and another to see if it was released. I'm a bit embarrased that I didn't realize this myself before I started crying like a baby, crouched in the fetal position...

Enlightenment is not something you earn, it's something you pay for the rest of your life.

Pumaman

Yeah, this is a bit inconsistent ... it's due to the way the operating system works, but AGS could probably work around it; I"m not sure if it should though.

YOke

No. As long as you make a note about the special workings of the numpad in the manual on the next version... ;)

Enlightenment is not something you earn, it's something you pay for the rest of your life.

SMF spam blocked by CleanTalk