Jump to content


Photo

Hey Are There Any Keycode To String Scripts?


  • Please log in to reply
10 replies to this topic

#1 Potnop

Potnop

    GMC Member

  • GMC Member
  • 3103 posts

Posted 13 March 2008 - 09:31 PM

(Heh weird, the first post dissapeared because of the damn server being busy when I submitted this)

OK, I did search, and found nothing...

Does anyone have a script that takes a keycode value and returns a string representing what key it is?

Like

vk_left is passed in and out comes "Left Key".

I'm trying to make a menu for setting the controls.

I could make this myself but that would be VERY tedious and I was wondering if there is one out already like that... Basically it would require a big switch statement I guess...

Heh, or is there a GM function built in that does this. I haven't found one in the help file, but I would so laugh if there is one...
  • 0
Vegeta! What does the scouter say about his powerlevel?!? It's ovER 9000!!!!!
I ownt read da script, script reads me.


Link To The Super Crew Topic / Link To Colonial Commando Topic
Platform Pathfinding Example Download it here!
Editable Early Version Level Editor(Nice @$$ stuff, check it out) Download it here!

#2 Pecok

Pecok

    GMC Member

  • New Member
  • 137 posts

Posted 13 March 2008 - 09:57 PM

Yea, I have a script for that. It only has all the numpad numbers, the letters, the arrow keys, and the space bar though... It's a good start for someone who wants to expand on it I guess.
Download here.

[edit]
I found this script made by LeGeNDaR here, just in case you dont want to mess with adding to mine.

Edited by Pecok, 13 March 2008 - 10:37 PM.

  • 0

#3 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 14 March 2008 - 02:07 AM

switch(argument0)

{

    case $00: { return "<none>"; } //none



    case $01: { return "LBUTTON"; } //Left mouse button



    case $02: { return "RBUTTON"; } //Right mouse button



    case $03: { return "CANCEL"; } //Control-break processing



    case $04: { return "MBUTTON"; } //Middle mouse button (three-button mouse: { return ""; } //

    case $05: { return "XBUTTON1"; } //Windows 2000/XP: { return ""; } X1 mouse button



    case $06: { return "XBUTTON2"; } //Windows 2000/XP: { return ""; } X2 mouse button



    case $08: { return "BACK"; } //BACKSPACE key



    case $09: { return "TAB"; } //TAB key



    case $0C: { return "CLEAR"; } //CLEAR key



    case $0D: { return "RETURN"; } //ENTER key



    case $10: { return "SHIFT"; } //SHIFT key



    case $11: { return "CONTROL"; } //CTRL key



    case $12: { return "MENU"; } //ALT key



    case $13: { return "PAUSE"; } //PAUSE key



    case $14: { return "CAPITAL"; } //CAPS LOCK key



    case $15: { return "HANGUL"; } //IME Hangul mode



    case $17: { return "JUNJA"; } //IME Junja mode



    case $18: { return "FINAL"; } //IME final mode



    case $19: { return "HANJA"; } //IME Hanja mode



    case $19: { return "KANJI"; } //IME Kanji mode



    case $1B: { return "ESCAPE"; } //ESC key



    case $1C: { return "CONVERT"; } //IME convert



    case $1D: { return "NONCONVERT"; } //IME nonconvert



    case $1E: { return "ACCEPT"; } //IME accept



    case $1F: { return "MODECHANGE"; } //IME mode change request



    case $20: { return "SPACE"; } //SPACEBAR



    case $21: { return "PRIOR"; } //PAGE UP key



    case $22: { return "NEXT"; } //PAGE DOWN key



    case $23: { return "END"; } //END key



    case $24: { return "HOME"; } //HOME key



    case $25: { return "LEFT"; } //LEFT ARROW key



    case $26: { return "UP"; } //UP ARROW key



    case $27: { return "RIGHT"; } //RIGHT ARROW key



    case $28: { return "DOWN"; } //DOWN ARROW key



    case $29: { return "SELECT"; } //SELECT key



    case $2A: { return "PRINT"; } //PRINT key



    case $2B: { return "EXECUTE"; } //EXECUTE key



    case $2C: { return "SNAPSHOT"; } //PRINT SCREEN key



    case $2D: { return "INSERT"; } //INS key



    case $2E: { return "DELETE"; } //DEL key



    case $2F: { return "HELP"; } //HELP key



    case $30: { return "0"; } //0 key



    case $31: { return "1"; } //1 key



    case $32: { return "2"; } //2 key



    case $33: { return "3"; } //3 key



    case $34: { return "4"; } //4 key



    case $35: { return "5"; } //5 key



    case $36: { return "6"; } //6 key



    case $37: { return "7"; } //7 key



    case $38: { return "8"; } //8 key



    case $39: { return "9"; } //9 key



    case $41: { return "A"; } //A key



    case $42: { return "B"; } //B key



    case $43: { return "C"; } //C key



    case $44: { return "D"; } //D key



    case $45: { return "E"; } //E key



    case $46: { return "F"; } //F key



    case $47: { return "G"; } //G key



    case $48: { return "H"; } //H key



    case $49: { return "I"; } //I key



    case $4A: { return "J"; } //J key



    case $4B: { return "K"; } //K key



    case $4C: { return "L"; } //L key



    case $4D: { return "M"; } //M key



    case $4E: { return "N"; } //N key



    case $4F: { return "O"; } //O key



    case $50: { return "P"; } //P key



    case $51: { return "Q"; } //Q key



    case $52: { return "R"; } //R key



    case $53: { return "S"; } //S key



    case $54: { return "T"; } //T key



    case $55: { return "U"; } //U key



    case $56: { return "V"; } //V key



    case $57: { return "W"; } //W key



    case $58: { return "X"; } //X key



    case $59: { return "Y"; } //Y key



    case $5A: { return "Z"; } //Z key



    case $5B: { return "LWIN"; } //Left Windows key (Microsoft Natural keyboard: { return ""; } 



    case $5C: { return "RWIN"; } //Right Windows key (Natural keyboard: { return ""; } //

    case $5D: { return "APPS"; } //Applications key (Natural keyboard: { return ""; } //

    case $5F: { return "SLEEP"; } //Computer Sleep key



    case $60: { return "NUMPAD0"; } //Numeric keypad 0 key



    case $61: { return "NUMPAD1"; } //Numeric keypad 1 key



    case $62: { return "NUMPAD2"; } //Numeric keypad 2 key



    case $63: { return "NUMPAD3"; } //Numeric keypad 3 key



    case $64: { return "NUMPAD4"; } //Numeric keypad 4 key



    case $65: { return "NUMPAD5"; } //Numeric keypad 5 key



    case $66: { return "NUMPAD6"; } //Numeric keypad 6 key



    case $67: { return "NUMPAD7"; } //Numeric keypad 7 key



    case $68: { return "NUMPAD8"; } //Numeric keypad 8 key



    case $69: { return "NUMPAD9"; } //Numeric keypad 9 key



    case $6A: { return "MULTIPLY"; } //Multiply key



    case $6B: { return "ADD"; } //Add key



    case $6C: { return "SEPARATOR"; } //Separator key



    case $6D: { return "SUBTRACT"; } //Subtract key



    case $6E: { return "DECIMAL"; } //Decimal key



    case $6F: { return "DIVIDE"; } //Divide key



    case $70: { return "F1"; } //F1 key



    case $71: { return "F2"; } //F2 key



    case $72: { return "F3"; } //F3 key



    case $73: { return "F4"; } //F4 key



    case $74: { return "F5"; } //F5 key



    case $75: { return "F6"; } //F6 key



    case $76: { return "F7"; } //F7 key



    case $77: { return "F8"; } //F8 key



    case $78: { return "F9"; } //F9 key



    case $79: { return "F10"; } //F10 key



    case $7A: { return "F11"; } //F11 key



    case $7B: { return "F12"; } //F12 key



    case $7C: { return "F13"; } //F13 key



    case $7D: { return "F14"; } //F14 key



    case $7E: { return "F15"; } //F15 key



    case $7F: { return "F16"; } //F16 key



    case $80: { return "F17"; } //F17 key



    case $81: { return "F18"; } //F18 key



    case $82: { return "F19"; } //F19 key



    case $83: { return "F20"; } //F20 key



    case $84: { return "F21"; } //F21 key



    case $85: { return "F22"; } //F22 key



    case $86: { return "F23"; } //F23 key



    case $87: { return "F24"; } //F24 key



    case $90: { return "NUMLOCK"; } //NUM LOCK key



    case $91: { return "SCROLL"; } //SCROLL LOCK key



    case $A0: { return "LSHIFT"; } //Left SHIFT key



    case $A1: { return "RSHIFT"; } //Right SHIFT key



    case $A2: { return "LCONTROL"; } //Left CONTROL key



    case $A3: { return "RCONTROL"; } //Right CONTROL key



    case $A4: { return "LMENU"; } //Left MENU key



    case $A5: { return "RMENU"; } //Right MENU key



    case $A6: { return "BRBACK"; } //Windows 2000/XP: { return ""; } Browser Back key



    case $A7: { return "BRFORWARD"; } //Windows 2000/XP: { return ""; } Browser Forward key



    case $A8: { return "BRREFRESH"; } //Windows 2000/XP: { return ""; } Browser Refresh key



    case $A9: { return "BRSTOP"; } //Windows 2000/XP: { return ""; } Browser Stop key



    case $AA: { return "BRSEARCH"; } //Windows 2000/XP: { return ""; } Browser Search key 



    case $AB: { return "BRFAVORITES"; } //Windows 2000/XP: { return ""; } Browser Favorites key



    case $AC: { return "BRHOME"; } //Windows 2000/XP: { return ""; } Browser Start and Home key



    case $AD: { return "VOLMUTE"; } //Windows 2000/XP: { return ""; } Volume Mute key



    case $AE: { return "VOLDOWN"; } //Windows 2000/XP: { return ""; } Volume Down key



    case $AF: { return "VOLUP"; } //Windows 2000/XP: { return ""; } Volume Up key



    case $B0: { return "MEDNEXT"; } //Windows 2000/XP: { return ""; } Next Track key



    case $B1: { return "MEDPREV"; } //Windows 2000/XP: { return ""; } Previous Track key



    case $B2: { return "MEDSTOP"; } //Windows 2000/XP: { return ""; } Stop Media key



    case $B3: { return "MEDPLAY"; } //Windows 2000/XP: { return ""; } Play/Pause Media key



    case $B4: { return "MAIL"; } //Windows 2000/XP: { return ""; } Start Mail key



    case $B5: { return "MEDIA"; } //Windows 2000/XP: { return ""; } Select Media key



    case $B6: { return "APP1"; } //Windows 2000/XP: { return ""; } Start Application 1 key



    case $B7: { return "APP2"; } //Windows 2000/XP: { return ""; } Start Application 2 key



    case $BA: { return "OEM (:)"; } //Used for miscellaneous characters; it can vary by keyboard.



    case $BB: { return "OEM (+)"; } //Windows 2000/XP: { return ""; } For any country/region, the '+' key



    case $BC: { return "OEM (,)"; } //Windows 2000/XP: { return ""; } For any country/region, the ',' key



    case $BD: { return "OEM (-)"; } //Windows 2000/XP: { return ""; } For any country/region, the '-' key



    case $BE: { return "OEM (.)"; } //Windows 2000/XP: { return ""; } For any country/region, the '.' key



    case $BF: { return "OEM (?)"; } //Used for miscellaneous characters; it can vary by keyboard.



    case $C0: { return "OEM (~)"; } //Used for miscellaneous characters; it can vary by keyboard. 





    case $DB: { return "OEM ([)"; } //Used for miscellaneous characters; it can vary by keyboard. 



    case $DC: { return "OEM (\)"; } //Used for miscellaneous characters; it can vary by keyboard. 



    case $DD: { return "OEM (])"; } //Used for miscellaneous characters; it can vary by keyboard. 



    case $DE: { return "OEM (')"; } //Used for miscellaneous characters; it can vary by keyboard. 



    case $E5: { return "PROCESS"; } //Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: { return ""; } IME PROCESS key



    case $E7: { return "PACKET"; } //Windows 2000/XP: { return ""; } Used to pass Unicode characters as if they were keystrokes. The PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP



    case $F6: { return "ATTN"; } //Attn key



    case $F7: { return "CRSEL"; } //CrSel key



    case $F8: { return "EXSEL"; } //ExSel key



    case $F9: { return "EREOF"; } //Erase EOF key



    case $FA: { return "PLAY"; } //Play key



    case $FB: { return "ZOOM"; } //Zoom key



    case $FD: { return "PA1"; } //PA1 key



    case $FE: { return "CLEAR"; } //Clear key

    

    default: { return "OEM ("+ string(argument0)+")"; }



}

  • 2

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#4 Potnop

Potnop

    GMC Member

  • GMC Member
  • 3103 posts

Posted 14 March 2008 - 03:29 AM

Niiice!!!

So the mouse buttons are also in the keycodes?

That makes it much easier because I want the user to also assign mouse button actions to some things!!!

I'm a little confused about some of them though...

Edited by Potnop, 14 March 2008 - 03:30 AM.

  • 0
Vegeta! What does the scouter say about his powerlevel?!? It's ovER 9000!!!!!
I ownt read da script, script reads me.


Link To The Super Crew Topic / Link To Colonial Commando Topic
Platform Pathfinding Example Download it here!
Editable Early Version Level Editor(Nice @$$ stuff, check it out) Download it here!

#5 xot

xot

    GMC Dismember

  • GMC Elder
  • 4785 posts
  • Version:GM:Studio

Posted 14 March 2008 - 05:03 AM

I'm not 100% that those literal codes are going to work on all keyboards. The vk_ constants may not actually be constant and my be dependent on OS, keyboard, country, etc.

So I made this in 30 seconds thanks to the miracle of regex replacement.

switch (argument0) {
    case vk_add: return "add";
    case vk_alt: return "alt";
    case vk_anykey: return "anykey";
    case vk_backspace: return "backspace";
    case vk_control: return "control";
    case vk_decimal: return "decimal";
    case vk_delete: return "delete";
    case vk_divide: return "divide";
    case vk_down: return "down";
    case vk_end: return "end";
    case vk_enter: return "enter";
    case vk_escape: return "escape";
    case vk_f1: return "f1";
    case vk_f10: return "f10";
    case vk_f11: return "f11";
    case vk_f12: return "f12";
    case vk_f2: return "f2";
    case vk_f3: return "f3";
    case vk_f4: return "f4";
    case vk_f5: return "f5";
    case vk_f6: return "f6";
    case vk_f7: return "f7";
    case vk_f8: return "f8";
    case vk_f9: return "f9";
    case vk_home: return "home";
    case vk_insert: return "insert";
    case vk_lalt: return "lalt";
    case vk_lcontrol: return "lcontrol";
    case vk_left: return "left";
    case vk_lshift: return "lshift";
    case vk_multiply: return "multiply";
    case vk_nokey: return "nokey";
    case vk_numpad0: return "numpad0";
    case vk_numpad1: return "numpad1";
    case vk_numpad2: return "numpad2";
    case vk_numpad3: return "numpad3";
    case vk_numpad4: return "numpad4";
    case vk_numpad5: return "numpad5";
    case vk_numpad6: return "numpad6";
    case vk_numpad7: return "numpad7";
    case vk_numpad8: return "numpad8";
    case vk_numpad9: return "numpad9";
    case vk_pagedown: return "pagedown";
    case vk_pageup: return "pageup";
    case vk_pause: return "pause";
    case vk_printscreen: return "printscreen";
    case vk_ralt: return "ralt";
    case vk_rcontrol: return "rcontrol";
    case vk_return: return "return";
    case vk_right: return "right";
    case vk_rshift: return "rshift";
    case vk_shift: return "shift";
    case vk_space: return "space";
    case vk_subtract: return "subtract";
    case vk_tab: return "tab";
    case vk_up: return "up";
    default: return chr(argument0);
}

1. Game Maker > Scripts > Show Constants
2. Regex replace: vk_(.*) With: case vk_$1: return "$1";
3. Add switch statement and two braces.
4. Add default case.

Edited by xot, 14 March 2008 - 05:15 AM.

  • 0
GMLscripts.com, rise from your grave!

If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.

#6 Potnop

Potnop

    GMC Member

  • GMC Member
  • 3103 posts

Posted 14 March 2008 - 05:39 AM

Hmm... so that one should work for sure?

I want to work with all keys including letters and stuff...

Yours doesn't have all...
  • 0
Vegeta! What does the scouter say about his powerlevel?!? It's ovER 9000!!!!!
I ownt read da script, script reads me.


Link To The Super Crew Topic / Link To Colonial Commando Topic
Platform Pathfinding Example Download it here!
Editable Early Version Level Editor(Nice @$$ stuff, check it out) Download it here!

#7 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 14 March 2008 - 05:59 AM

Some letter keys (such as [, ], :, ~ and so on) will have different code from keyboard to keyboard (some keyboards even have no single key code for them.) In case you plan to use keys those have no corresponding vk_ constants, you'd better ask the keyboard driver itself the name of the key. I made a DLL for it a while back: KeyName.zip

As to icuurd's one, I figure it is straightly copied from one of virtual keycode table out there. Mind that not all of them might work in Game Maker. (For instance, $01 is vk_any in GM. Those codes which refer to mouse buttons can only be used in other programming language which is capable to handle Windows message directly.) It also contains a number of non-existing keys those only exist in a specification, e.g. F13 through F24 are deprecated keys those no practical keyboard have.

Edited by torigara, 15 January 2011 - 04:42 PM.

  • 0

#8 xot

xot

    GMC Dismember

  • GMC Elder
  • 4785 posts
  • Version:GM:Studio

Posted 14 March 2008 - 06:01 AM

Hmm... so that one should work for sure?

I want to work with all keys including letters and stuff...

Yours doesn't have all...

<{POST_SNAPBACK}>


Yeah, it only works for the vk_ codes and digit keys and letter keys. Other keys will return undefined values that are keyboard dependent. A smarter default case would probably be a good idea.
  • 0
GMLscripts.com, rise from your grave!

If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.

#9 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 14 March 2008 - 06:20 AM

the codes work for keyboard_check_direct... Even the mouse click which is greaaaat.

the codes do work with keyboard_check, aside for the non keyboard values (ignored by all but _direct)... so you should get the right returns if used with all keyboard fns


When in doubt, try it out...

Edited by icuurd12b42, 14 March 2008 - 06:26 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#10 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 14 March 2008 - 07:14 AM

the codes work for keyboard_check_direct... Even the mouse click which is greaaaat.

(snip)

When in doubt, try it out...

<{POST_SNAPBACK}>

Well, of course I tested it in prior to posting, but I seem to have missed the instruction that some of them will only work for keyboard_check_direct.

Hmm, it means that keyboard_check_direct(vk_anykey) doesn't work as expected (it results in true when the mouse button is pressed, as opposed to any key.) A curious result; I would memorize it for troubleshooting someone in the future...

Edited by torigara, 14 March 2008 - 07:18 AM.

  • 0

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 14 March 2008 - 07:33 AM

the codes work for keyboard_check_direct... Even the mouse click which is greaaaat.

(snip)

When in doubt, try it out...

<{POST_SNAPBACK}>

Well, of course I tested it in prior to posting, but I seem to have missed the instruction that some of them will only work for keyboard_check_direct.

Hmm, it means that keyboard_check_direct(vk_anykey) doesn't work as expected (it results in true when the mouse button is pressed, as opposed to any key.) A curious result; I would memorize it for troubleshooting someone in the future...

<{POST_SNAPBACK}>


If you ask me it's the other functions like mouse_check that dont work as expected
1 for left
2 for right
4 for middle
8 for extra1
16 for extra2...

Thank god for that function is intact (not fiddled with and going straight to the way windows work)... I've cut down on the number of calls by merging mouse check and key checks into one call AND I can now support all the mouse buttons you may have AND, though useles in game, act on all my laptop buttons like mail, browse, media, media next... Some useless since they start applications... Media Next works as a game button though... As long as media player is not playing LOL.

Edited by icuurd12b42, 14 March 2008 - 07:34 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button