Jump to content


Photo

Keboard_key_getname


  • Please log in to reply
10 replies to this topic

#1 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 22 July 2008 - 04:17 PM

Hello, i was figuring about how to make customizeble controlls, and figured "Wouldnt it be cool if you saw the name of the key?"
so i started to se what keycodes went to what jey, and created this array based script:

/*Created by Headline
this one i worked REALLY hard on, so credits is needed :P

usage:
keboard_key_getname(keycode)

it returns the name of the key that keyboard_lastkey is returning.
(if the key isnt listed here, it will return "Unknown Key")
*/
var _key, name, i, o, return_value;
o=0
_key[0]=91
name[0]="Windows button"
_key[1]=27
name[1]="ESC"
_key[2]=220
name[2]="`"
_key[3]=219
name[3]="="
_key[4]=16
name[4]="Shift"
_key[5]=48
name[5]="0"
_key[6]=49
name[6]="1"
_key[7]=50
name[7]="2"
_key[8]=51
name[8]="3"
_key[9]=52
name[9]="4"
_key[10]=53
name[10]="5"
_key[11]=54
name[11]="6"
_key[12]=55
name[12]="7"
_key[13]=56
name[13]="8"
_key[14]=57
name[14]="9"
_key[15]=187
name[15]="-"
_key[16]=112
name[16]="F1"
_key[17]=113
name[17]="F2"
_key[18]=114
name[18]="F3"
_key[19]=115
name[19]="F4"
_key[20]=116
name[20]="F5"
_key[21]=117
name[21]="F6"
_key[22]=118
name[22]="F7"
_key[23]=119
name[23]="F8"
_key[24]=120
name[24]="F9"
_key[25]=121
name[25]="F10"
_key[26]=122
name[26]="F11"
_key[27]=123
name[27]="F12"
_key[28]=65
name[28]="A"
_key[29]=66
name[29]="B"
_key[30]=67
name[30]="C"
_key[31]=68
name[31]="D"
_key[32]=69
name[32]="E"
_key[33]=70
name[33]="F"
_key[34]=71
name[34]="G"
_key[35]=72
name[35]="H"
_key[36]=73
name[36]="I"
_key[37]=74
name[37]="J"
_key[38]=75
name[38]="K"
_key[39]=76
name[39]="L"
_key[40]=77
name[40]="M"
_key[41]=78
name[41]="N"
_key[42]=79
name[42]="O"
_key[43]=80
name[43]="P"
_key[44]=81
name[44]="Q"
_key[45]=82
name[45]="R"
_key[46]=83
name[46]="S"
_key[47]=84
name[47]="T"
_key[48]=85
name[48]="U"
_key[49]=86
name[49]="V"
_key[50]=87
name[50]="W"
_key[51]=88
name[51]="X"
_key[52]=89
name[52]="Y"
_key[53]=90
name[53]="Z"
_key[54]=91
name[54]="END"
_key[55]=34
name[55]="Page Down"
_key[56]=33
name[56]="Page Up"
_key[57]=36
name[57]="Home"
_key[58]=46
name[58]="Delete"
_key[59]=45
name[59]="Insert"
_key[60]=19
name[60]="Pause"
_key[61]=3
name[61]="Break"
_key[62]=226
name[62]="Left \"
_key[63]=189
name[63]="/"
_key[64]=191
name[64]="Right \"
_key[65]=20
name[65]="Caps Lock"
_key[66]=144
name[66]="Num Lock"
_key[67]=145
name[67]="Scroll Lock"
_key[68]=17
name[68]="CTRL"
_key[69]=18
name[69]="ALT"
_key[70]=221
name[70]="["
_key[71]=222
name[71]="'"
_key[72]=192
name[72]=";"
_key[73]=37
name[73]="Left"
_key[74]=38
name[74]="Up"
_key[75]=39
name[75]="Right"
_key[76]=40
name[76]="Down"
_key[77]=96
name[77]="Num 0"
_key[78]=97
name[78]="Num 1"
_key[79]=98
name[79]="Num 2"
_key[80]=99
name[80]="Num 3"
_key[81]=100
name[81]="Num 4"
_key[82]=101
name[82]="Num 5"
_key[83]=102
name[83]="Num 6"
_key[84]=103
name[84]="Num 7"
_key[85]=104
name[85]="Num 8"
_key[86]=105
name[86]="Num 9"
_key[87]=106
name[87]="Num *"
_key[88]=107
name[88]="Num +"
_key[89]=108
name[89]="Num Enter"
_key[90]=109
name[90]="Num -"
_key[91]=110
name[91]="Num ,"
_key[92]=32
name[92]="Space"
_key[93]=8
name[93]="Backspace"
_key[94]=13
name[94]="Enter"
_key[95]=93
name[95]="Menu"
for(i=0;1;i+=1)
{
	if(i>94)
	{
		return_value="Unknown Key";
		break;
	}
	if(_key[i]=argument0)
		{
		return_value=name[i];
		break;
	}
}
return return_value;

Feel free to use it, but PLEASE credit me :P i worked hard on this one.

EDIT 1: I found that there was a problem with X, Y and Z... that is now corrected!

Edited by headline@live.se, 27 July 2008 - 03:13 PM.

  • 0
92% of the population has moved to Rap. If you are one of the 8% that has stuck to rock, put this in your sig. RAP SUCKS!

keyboard_get_keyname

#2 sound_logic

sound_logic

    GMC Member

  • New Member
  • 274 posts

Posted 22 July 2008 - 05:10 PM

Nice, useful, one problem, on some keyboards it won't work, but that should work for most windows keyboards. To be frank, you have WAY to much time on your hands to create that. Still, looks useful.
  • 0

#3 posva

posva

    GMC Member

  • New Member
  • 610 posts
  • Version:GM8

Posted 22 July 2008 - 09:07 PM

anyone can do this by itself ... why do you think people will credit you?

script is a simple function , it's not bad
  • 0

#4 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 22 July 2008 - 09:30 PM

Well, it only took a couple of hours, and i needed it for my game :P
Ofc anyone can create it by themself, witch means that i cant tell if someone is using this script or their own, however i would like credit since i helped ppl out so the doesnt need to do this. (and if anyone finds that a key is wrong/missing, please tell me :P)
  • 0
92% of the population has moved to Rap. If you are one of the 8% that has stuck to rock, put this in your sig. RAP SUCKS!

keyboard_get_keyname

#5 posva

posva

    GMC Member

  • New Member
  • 610 posts
  • Version:GM8

Posted 23 July 2008 - 07:58 PM

Ok
  • 0

#6 ionel71089

ionel71089

    GMC Member

  • New Member
  • 96 posts

Posted 26 August 2008 - 05:25 AM

Aw ... You kind used more arrays than needed ... you could just have used name[key code]="name" ... so instead of _key[1]=27 name[1]="ESC" you could just say name[27]="ESC".
  • 0
Currently looking for : voice actors for my Rubik's Cube Tutorial.
GM Quiz!

#7 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 26 August 2008 - 05:41 AM

Uhmm, yea. i will look into that (the problem is that if i missed a key, or if a country has more keys, it will return an "Array out of bounds" BUT if you use 2 arrays it is easier to make an "Unkown key" check)
  • 0
92% of the population has moved to Rap. If you are one of the 8% that has stuck to rock, put this in your sig. RAP SUCKS!

keyboard_get_keyname

#8 ionel71089

ionel71089

    GMC Member

  • New Member
  • 96 posts

Posted 26 August 2008 - 05:49 AM

Uhmm, yea. i will look into that (the problem is that if i missed a key, or if a country has more keys, it will return an "Array out of bounds" BUT if you use 2 arrays it is easier to make an "Unkown key" check)


Well... you could just initialize a 256 array with the string "N/A" or something and let the user tell you the name in that case.
I don't think that there are more than 256 character ... mostly because char is 8-bit.
  • 0
Currently looking for : voice actors for my Rubik's Cube Tutorial.
GM Quiz!

#9 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 26 August 2008 - 06:14 PM

hmm, maybe... but not now, but in the future
  • 0
92% of the population has moved to Rap. If you are one of the 8% that has stuck to rock, put this in your sig. RAP SUCKS!

keyboard_get_keyname

#10 weckar

weckar

    Helping Hand

  • GMC Member
  • 2616 posts
  • Version:Unknown

Posted 26 August 2008 - 06:29 PM

you realise this would only work on QWERTYs, and not even all of those?
  • 0
Just had my 10-year forum anniversary. Feeling - Even - Older.
Awards & Recognitions:
Spoiler

[I have a nasty habit of writing "it is" simply as "it". Please forgive me, I try to avoid it.]

#11 headline@live.se

headline@live.se

    GMC Member

  • New Member
  • 1298 posts

Posted 26 August 2008 - 06:38 PM

well, it does work on all keyboards, just that it doesnt show the correct key on all keyboards :P however this is better than nothing ::lmao::
  • 0
92% of the population has moved to Rap. If you are one of the 8% that has stuck to rock, put this in your sig. RAP SUCKS!

keyboard_get_keyname