Author Topic: Keycode conundrum *SOLVED*  (Read 567 times)  Share 

YOke

  • 26 orbits and beginning to get dizzy...
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Keycode conundrum *SOLVED*
« on: 29 Nov 2004, 21:14 »
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.  ::)
« Last Edit: 29 Nov 2004, 23:46 by YOke »

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

Ashen

Re: Keycode conundrum
« Reply #1 on: 29 Nov 2004, 21:42 »
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.
« Last Edit: 29 Nov 2004, 21:44 by Ashen »
I know what you're thinking ... Don't think that.

YOke

  • 26 orbits and beginning to get dizzy...
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: Keycode conundrum
« Reply #2 on: 29 Nov 2004, 21:57 »
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

  • Creator of AGS
  • Administrator
  • Mittens TRAITOR
  • I sense danger.
    • Lifetime Achievement Award Winner
    •  
Re: Keycode conundrum
« Reply #3 on: 29 Nov 2004, 22:02 »
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

  • 26 orbits and beginning to get dizzy...
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: Keycode conundrum
« Reply #4 on: 29 Nov 2004, 22:11 »
I am indeed using IsKeyPressed.

This is for checking the release of a key.
[code]
if ((IsKeyPressed(lastkeypressed) != 1) && (iskeyreleased == 1))
   {
     iskeyreleased = 0;
     lastkeypressed = 0;
     SetGlobalInt(66, 0);
   }
[/code]

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! :)
« Last Edit: 29 Nov 2004, 22:20 by YOke »

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

Ashen

Re: Keycode conundrum
« Reply #5 on: 29 Nov 2004, 22:15 »
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.
« Last Edit: 30 Nov 2004, 23:47 by Ashen »
I know what you're thinking ... Don't think that.

YOke

  • 26 orbits and beginning to get dizzy...
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: Keycode conundrum *SOLVED*
« Reply #6 on: 01 Dec 2004, 20:39 »
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

  • Creator of AGS
  • Administrator
  • Mittens TRAITOR
  • I sense danger.
    • Lifetime Achievement Award Winner
    •  
Re: Keycode conundrum *SOLVED*
« Reply #7 on: 01 Dec 2004, 22:04 »
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

  • 26 orbits and beginning to get dizzy...
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with web design
    •  
Re: Keycode conundrum *SOLVED*
« Reply #8 on: 02 Dec 2004, 11:11 »
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.