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 2 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.
virtual_key_add(x, y, w, h, keycode);
|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|
index of virtual key
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.