Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
0
Members

[help] Is there a way to get the "name" of an input key? (solved)

A topic by Doomcaster created Mar 23, 2016 Views: 918 Replies: 6
Viewing posts 1 to 4

I've almost completed my keyboard configuration code, but I need a way to properly retrieve the input from the player. Currently I'm using Sup.Input.getTextEntered() and it works pretty good the way I have it setup. The problem is, characters like ";" or "," can't be used with Sup.Input.wasKeyJustPressed() because it expects "SEMICOLON" and "COMMA". Is there an easier way to retrieve "KEYNAME" besides storing the characters in an array and manually converting them to their proper input names?

(+1)

I'm not sure if there's an easy way to do this, but if you need a list of all the special key names, there's a comment in the TypeScript API browser in Sup.Input that says:

 // Valid key names (based on window.KeyEvent.DOM_VK_*):
// CANCEL, HELP, BACK_SPACE, TAB, CLEAR, RETURN, SHIFT, CONTROL, ALT,
// PAUSE, CAPS_LOCK, ESCAPE, SPACE, PAGE_UP, PAGE_DOWN, END, HOME,
// LEFT, UP, RIGHT, DOWN, PRINTSCREEN, INSERT, DELETE,
// 0 to 9, SEMICOLON, EQUALS, A to Z,
// CONTEXT_MENU, NUMPAD0 to NUMPAD9,
// MULTIPLY, ADD, SEPARATOR, SUBTRACT, DECIMAL, DIVIDE,
// F1 to F24, NUM_LOCK, SCROLL_LOCK, COMMA, PERIOD, SLASH, BACK_QUOTE,
// OPEN_BRACKET, BACK_SLASH, CLOSE_BRACKET, QUOTE, META
//
// Additionnally, ANY will return true for any key
// and NONE will return true for no keys
(1 edit)

There's a list like that in the source code too. The problem is, there's no easy way to access it since it's not stored. I was hoping to avoid it, but it seems like I might have to do it manually and check each value after all. :P

Regardless, thanks for looking into it :)

(+1)
Don't know if this will work but maybe try:

Sup.log((Sup.Input.getTextEntered()))

Yep I tried that. It's part of what I have currently. It works very well with letters and numbers if you convert it to uppercase before passing it to input, but it doesn't handle special characters or things that don't insert characters, like the arrow keys or shift.

(1 edit)

I ended up storing the acceptable values in an array and cycling through each one with Sup.Input.wasKeyJustPressed() in a for-loop. Works really well, although it seems SEMICOLON, ADD, and SUBTRACT/EQUALS, aren't detected at all and doesn't resond to being pressed. But In any case, I got it working :D

(+1)

That's very strange. :/ But at least you got it to work. :D