virtual_key_add

Creates a virtual key with a set area and keycode, returning its id.

Syntax:

virtual_key_add(x, y, w, h, keycode);


Argument Description
x The x coordinate (left side) of the virtual key on the screen
y The y coordinate (top side) of the virtual key on the screen
w The width of the virtual key
h The height of the virtual key
keycode Which keyboard key event should be triggered by touching this area


Returns: index of virtual key


Description

This function enables you to map "touches" of a screen area to keyboard events. This means that once you have assigned an area to a virtual key, all touches on that area will trigger the keyboard event corresponding to the key you have mapped to the area. You can assign each virtual key you define to a variable too, which can then be used in the further virtual key functions to show, hide and delete them. These keys are assigned on a per room basis and will be automatically removed by GameMaker: Studio when changing rooms.

The actual position of the virtual key is based on the screen position rather than room position and so the x/y values are absolute on the screen. This means that you don't need to worry about the use of views or the relative room coordinates, and can simply draw your key sprites and define your virtual keys in the Draw GUI Event of an object.


Example:

global.Left = virtual_key_add(32, 32, 64, 64, vk_left);

The above code creates a virtual key 64x64 pixels square, positioned on the screen at (32, 32) which will trigger the vk_left event when touched and assigns the index of this virtual key to a global variable.


Back: Virtual Keys
Next: virtual_key_show
© Copyright YoYo Games Ltd. 2018 All Rights Reserved