Jump to content


Photo

Gamemaker Keyboard Key Codes


  • Please log in to reply
13 replies to this topic

#1 Keysle

Keysle

    GMC Member

  • GMC Member
  • 208 posts

Posted 08 September 2010 - 01:56 AM

Where can I find a full list of the key codes for game maker.
I know Shift = 16
I know Ctrl = 17
I know Alt = 18

It's tedious to type in every character. especially when I don't have all the keyboard characters for everytype of keyboard

i need it for doing custom controls on my game.
is there a list i can use?
  • 0
Posted ImagePosted Image

#2 FmMan3

FmMan3

    GMC Member

  • GMC Member
  • 189 posts
  • Version:GM:Studio

Posted 08 September 2010 - 02:04 AM

Here is an article from the Game Maker help file.

Search: keyboard_check and you'll see a nice help document.

To put it simply, what it says below is: If you want to check if a certain letter is pressed use the following -
keyboard_check(ord('A'));

What ord() does is return the ascii code for that letter so you don't have to fill out the ascii code yourself.

For checking shift, control and alt, instead of using the ascii, simply use "vk_shift", "vk_control" and "vk_alt.
An example of their use would be
keyboard_check(vk_control);

The following constants for virtual keycodes exist: 


vk_nokey keycode representing that no key is pressed
vk_anykey keycode representing that any key is pressed
vk_left keycode for left arrow key
vk_right keycode for right arrow key
vk_up keycode for up arrow key
vk_down keycode for down arrow key
vk_enter enter key
vk_escape escape key
vk_space space key
vk_shift shift key
vk_control control key
vk_alt alt key
vk_backspace backspace key
vk_tab tab key
vk_home home key
vk_end end key
vk_delete delete key
vk_insert insert key
vk_pageup pageup key
vk_pagedown pagedown key
vk_pause pause/break key
vk_printscreen printscreen/sysrq key
vk_f1 ... vk_f12 keycodes for the function keys F1 to F12
vk_numpad0 ... vk_numpad9 number keys on the numeric keypad
vk_multiply multiply key on the numeric keypad
vk_divide divide key on the numeric keypad
vk_add add key on the numeric keypad
vk_subtract subtract key on the numeric keypad
vk_decimal decimal dot keys on the numeric keypad

For the letter keys use for example ord('A'). (The capital letters.) For the digit keys use for example ord('5') to get the <5> key. The following constants can only be used in keyboard_check_direct: 


vk_lshift left shift key
vk_lcontrol left control key
vk_lalt left alt key
vk_rshift right shift key
vk_rcontrol right control key
vk_ralt right alt key

Edited by FmMan3, 08 September 2010 - 02:10 AM.

  • 0
Signatures are nothing but a fad.

#3 IsmAvatar

IsmAvatar

    Good Samaritan

  • GMC Member
  • 2411 posts
  • Version:GM8

Posted 08 September 2010 - 03:11 AM

If you must know the values of the constants for some esoteric purpose, they are the same as Microsoft's Virtual Key Codes.
http://msdn.microsof...y/ms927178.aspx

However, I would highly advise finding ways to avoid hard-coding those numbers, using instead the built in constants and keyboard_key, among other things. Please also consider the post above me.
  • 2
Posted Image LateralGM is an IDE for editing GM files on Linux, Mac, and Windows.
We also house the GM File Format Documentation and other projects of that nature.
IsmAvatar.com | Examples | Scripts | Particles | DLLs | Credit Me
Email | Registered

#4 Keysle

Keysle

    GMC Member

  • GMC Member
  • 208 posts

Posted 08 September 2010 - 03:33 AM

I'll just set associated string like this

global.key_arr[vk_nokey]="No Key";
global.key_arr[vk_leftkey]="<-";
global.key_arr[vk_escape]="esc";
...

thanks for the help. I knew those existed, but not for letters. It's the same for capital and lower case I assume. I made a key reader and it couldn't detect uppercase letters anyway
  • 0
Posted ImagePosted Image

#5 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 08 September 2010 - 05:07 AM

I'll just set associated string like this

global.key_arr[vk_nokey]="No Key";
global.key_arr[vk_leftkey]="<-";
global.key_arr[vk_escape]="esc";
...

thanks for the help. I knew those existed, but not for letters. It's the same for capital and lower case I assume. I made a key reader and it couldn't detect uppercase letters anyway


I made a script for this sort of thing. The link in in my tools page.
  • 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


#6 e-effect

e-effect

    GMC Member

  • GMC Member
  • 37 posts
  • Version:Unknown

Posted 29 January 2011 - 05:28 PM

I know this is an old topic, but I was searching for the same information and found it. Thought others might want to know as well.

http://msdn.microsof...ms.keys(v=vs.71).aspx
  • 0

Co-creator of the new PC fighting game DPRN: Dinopirates vs Roboninjas, A Game Like No Other!

 

"This is a fun, deep fighter.  Complication doesn’t come from execution, as the moves are easy to learn...within lies a great title for entry level gamers and pros alike." - Indie-Love


#7 icuurd12b42

icuurd12b42

    Self Formed Sentient

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

Posted 30 January 2011 - 12:57 AM

I know this is an old topic, but I was searching for the same information and found it. Thought others might want to know as well.

http://msdn.microsof...ms.keys(v=vs.71).aspx


Yeah, I have a topic in my tools page with a function for all those...
  • 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


#8 HexZyle

HexZyle

    GMC Member

  • GMC Member
  • 255 posts
  • Version:GM:Studio

Posted 24 October 2012 - 07:43 AM

Seeing as this is a top google search, I'm going to put this here:

BCKSPC = 8

num5(no num lock) = 12
ENTER = 13

SHIFT = 16
CTRL = 17
ALT = 18
PAUSE = 19
CAPS = 20

SPACE = 32
PGUP = 33
PGDN = 34
END = 35
HOME = 36

LEFT = 37
UP = 38
RIGHT = 39
DOWN = 40

INS = 45
DEL = 46

0 = 48
1 = 49
2 = 50
3 = 51
4 = 52
5 = 53
6 = 54
7 = 55
8 = 56
9 = 57

A = 65
B = 66
C = 67
D = 68
E = 69
F = 70
G = 71
H = 72
I = 73
J = 74
K = 75
L = 76
M = 77
N = 78
O = 79
P = 80
Q = 81
R = 82
S = 83
T = 84
U = 85
V = 86
W = 87
X = 88
Y = 89
Z = 90
WINDOWS = 91

CNTXMENU = 93

NUM0 = 96
NUM1 = 97
NUM2 = 98
NUM3 = 99
NUM4 = 100
NUM5 = 101
NUM6 = 102
NUM7 = 103
NUM8 = 104
NUM9 = 105

NUM* = 106
NUM+ = 107
NUM- = 109
NUM. = 110
NUM/ = 111


F2 = 113
F3 = 114
F4 =
F5 =
F6 =
F7 = 118
F8 = 119
F9 =
F10 = 121
F11 = 122
F12 =

NUMLOCK = 144

; = 186
= = 187
, = 188
- = 189
. = 190
/ = 191
` = 192

[ = 219
\ = 220
] = 221
' = 222

Apologies for the necro.

Edited by HexZyle, 24 October 2012 - 07:45 AM.

  • 2

Check out nevereal.net for updates on Wuka World 2!


#9 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 2937 posts
  • Version:Unknown

Posted 24 October 2012 - 09:12 AM

Please do not use hard coded numbers as the constants may change on different platforms and you may not get the character you think you will get...

use the constants in the code as the compiler may remap them for the target platform, the only values we will honour are the A-Z and 0-9 values everything else can (and will be remapped).

Russell
  • 1

#10 jeremytq

jeremytq

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8.1

Posted 15 November 2013 - 01:01 AM

Here is an article from the Game Maker help file.

Search: keyboard_check and you'll see a nice help document.

To put it simply, what it says below is: If you want to check if a certain letter is pressed use the following -

keyboard_check(ord('A'));
What ord() does is return the ascii code for that letter so you don't have to fill out the ascii code yourself.

For checking shift, control and alt, instead of using the ascii, simply use "vk_shift", "vk_control" and "vk_alt.
An example of their use would be
keyboard_check(vk_control);
The following constants for virtual keycodes exist: 


vk_nokey keycode representing that no key is pressed
vk_anykey keycode representing that any key is pressed
vk_left keycode for left arrow key
vk_right keycode for right arrow key
vk_up keycode for up arrow key
vk_down keycode for down arrow key
vk_enter enter key
vk_escape escape key
vk_space space key
vk_shift shift key
vk_control control key
vk_alt alt key
vk_backspace backspace key
vk_tab tab key
vk_home home key
vk_end end key
vk_delete delete key
vk_insert insert key
vk_pageup pageup key
vk_pagedown pagedown key
vk_pause pause/break key
vk_printscreen printscreen/sysrq key
vk_f1 ... vk_f12 keycodes for the function keys F1 to F12
vk_numpad0 ... vk_numpad9 number keys on the numeric keypad
vk_multiply multiply key on the numeric keypad
vk_divide divide key on the numeric keypad
vk_add add key on the numeric keypad
vk_subtract subtract key on the numeric keypad
vk_decimal decimal dot keys on the numeric keypad

For the letter keys use for example ord('A'). (The capital letters.) For the digit keys use for example ord('5') to get the <5> key. The following constants can only be used in keyboard_check_direct: 


vk_lshift left shift key
vk_lcontrol left control key
vk_lalt left alt key
vk_rshift right shift key
vk_rcontrol right control key
vk_ralt right alt key

Hey, i'm trying to make the numpad key #9 shoot something when shift and numpad9 are both being pushed, and so far it works with the arrow keys, but I cant get the numpad to work? I'm doing keyboard_check_pressed(vk_numpad9), I also tried some other things and nothing is working.


  • 0

#11 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 13885 posts
  • Version:GM:Studio

Posted 15 November 2013 - 02:26 AM

Why does this get necroed more than 1 year after the last post nearly every time it gets necroed?

 

 

if keyboard_check_pressed(vk_numpad9)

if keyboard_check(vk_shift) //or keyboard_check_direct(vk_lshift) unless Studio fixed that

{ do whatever }

 

 

If that doesn't work, your issue may be you have the NumPad key toggled. I think there's a GM option to check that, but I'm not sure.


  • 0

"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong

 

"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis

 

"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis


#12 jeremytq

jeremytq

    GMC Member

  • New Member
  • 2 posts
  • Version:GM8.1

Posted 15 November 2013 - 04:59 AM

I'm actually using 8.1, because I heard studio only allows 20 sprites.

 

This is my code-

if keyboard_check(vk_shift) && keyboard_check_pressed(vk_numpad7) && arrows >=1
instance_create(x, y, Obj_Arrow_UpLeft)
arrows -= 1
}
 
The shift is working fine, which i know because I originally had it as the up and left arrow keys. 

  • 0

#13 Kimidori

Kimidori

    Opened Ultimate Gate

  • GMC Member
  • 552 posts
  • Version:GM8

Posted 13 February 2014 - 01:14 PM

^ GM studio indeed only allow 20 sprite... on free version, if you buy standard or pro you can use more.

 

and yeah I know I necro'ed this again but someone who don't know studio might misunderstand things when he found this thread.


  • 0

No matter what, cute is justice. If you're watching shows without moe, you should really be questioning your life decisions. The creation of 2D anime girls is the pinnacle of human achievement.


#14 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 13885 posts
  • Version:GM:Studio

Posted 13 February 2014 - 03:18 PM

At least it was necroed less than a year later.  :devil:  :skull:


  • 0

"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong

 

"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis

 

"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis