SOLVED: function called by pressing the ctrl key while walking

Started by johanvepa, Thu 29/05/2014 14:57:22

Previous topic - Next topic

johanvepa

Is there a way to call a function by pressing ctrl-arrowkey? or shift-arrowkey?

I've toyed with using on_key_press in rep_exec, but on_key_press seems to be tied to certain predefined ctrl-keys, like ctrl-A, not ctrl-[anything].

EDIT: I'd better explain what I' trying to do. Character is walking in key pressing mode, instead of the default tapping mode. I want an animation to figure when character is walking and a key is pressed. Also, the animation must be defined by the direction character is walking. I guess the simplest way is to use pressing mode for walking and then tapping or holding a key like shift or ctrl. I guess a function in rep_exec can do that, but how to code what key pressings call the function?

Khris

This works for me:

Code: ags
// in rep_exe
  bool shift = IsKeyPressed(403) || IsKeyPressed(404);
  bool ctrl = IsKeyPressed(405) || IsKeyPressed(406);

  if (ctrl && IsKeyPressed(eKeyLeftArrow)) Display("You pressed Ctrl + Left Arrow");

johanvepa

Well I'll be damned if you didn't just answer even before I could edit my own posting!

Khris, you must be the fastest typer in the west.


Oh, and thank you.

johanvepa

Oh, and by the way, where on earth do I find a list of what numbers the keyboard keys are defined as?

johanvepa

Quote from: Khris on Thu 29/05/2014 15:03:41
This works for me:

Code: ags
// in rep_exe
  bool shift = IsKeyPressed(403) || IsKeyPressed(404);
  bool ctrl = IsKeyPressed(405) || IsKeyPressed(406);

  if (ctrl && IsKeyPressed(eKeyLeftArrow)) Display("You pressed Ctrl + Left Arrow");


I guess this is not possible?

Code: ags
// in rep_exe
  if (IsKeyPressed(ctrl) && IsKeyPressed(eKeyLeftArrow)) Display("You pressed Ctrl + Left Arrow");


EDIT: Sorry, dumb question. Of course it isn't when ctrl is not on the list that pops up in AGS.

Khris

I just happened to check the Beginner's section right after you posted :)

The list of keycodes is in the manual under Reference -> ASCII code table (it is also linked to in IsKeyPressed()'s entry ;)).

Ctrl not being part of the list has nothing to do with it; Ctrl is a so-called modifier key, that's why it won't work with on_key_press. It still has its own keycode though.

You can do this just fine:
Code: ags
  if (IsKeyPressed(405) && IsKeyPressed(eKeyLeftArrow)) Display("You pressed Ctrl + Left Arrow");

However, the two ctrl keys have different codes and my version checks both while the above only checks for the left Ctrl key.

Btw, what you're trying to do is a bit more complicated than you think; for instance you can't change the character's view or animation speed while walking. That's why i wrote this: Alternative KeyboardMovement

johanvepa

Thanks a lot, Khris. I'm trying a lot of new things out here.

johanvepa

Tested and working ... so far. I've come across a weird error, but I'll come back when I'm further in my process   :)

SMF spam blocked by CleanTalk