How do i get which key is assigned for a control through block/code

Bombini

  • *
  • Posts: 1181
Hi guys,
i would like to know a code snippet or block with which i can get "which key is assigned for a control".
Basically reading/having the information.  For example of control "Shoot" where the result would be "X".

How do i do that?
Cheers!

Luyren

  • *
  • Posts: 1538
I haven't double checked, but this in particular changed from what's in the API for 3.5. To get the key code, I believe it's this:
Code: [Select]
Input.getKeys(Name of control)You have to then convert that key code to the key name, with this:
Code: [Select]
com.stencyl.Key.nameOfKey(keycode);You can combine both:
Code: [Select]
com.stencyl.Key.nameOfKey(Input.getKeys(name of control));
I have a behavior with a lot of customization for keyboard/gamepad binding menus, if you end up having trouble with this particular subject.
Working.

Bombini

  • *
  • Posts: 1181
Thanks!

i understand this (example for keyname down):
Quote
Input.getKeys("down")

Which spits out a number for the key.

I dont understand the rest though.
Like this? but this does not work:
Quote
com.stencyl.Key.nameOfKey(Input.getKeys("down"))
Thanks!

Luyren

  • *
  • Posts: 1538
What errors are you getting, and what build are you on?

I'm not well versed with code, and I had a lot of help from Justin to get the new control functions working on my end.
I think getKeys returns a list of all the mapped keys. So try adding a 0 in brackets at the end, like so:

Code: [Select]
com.stencyl.Key.nameOfKey(Input.getKeys("down")[0]);
If that still doesn't work, post whatever error you are getting. That can help pinpoint where the error could be.
Working.

Bombini

  • *
  • Posts: 1181
Hm...i tried but cant get it to work.
Your example spits out a standard compilation error which point to the line with the code.
Any other idea?

Luyren

  • *
  • Posts: 1538
Try removing the semicolon. That's the best I got.
Working.

Bombini

  • *
  • Posts: 1181
That must have been the only variant i didnt try ;)
Thanks so much. It works!