Virtual Keys And Virtual Keyboards

When developing games for touchscreen devices, it's often important to get keyboard input from the user. When using GameMaker Studio 2 this can be done in one of two ways:

What you use will depend very much on the game and what you need, but in general you would use virtual keys when you want to have onscreen buttons for player control or for menus, while you'd use the virtual keyboard when you need player input, like getting a name or setting a value.

In order for your games to work properly on mobile devices with a touch screen, you may need to be able to assign areas of the screen to respond to certain things when they are touched by the user. This is done by assigning a "virtual Key" to an internally mapped standard keyboard key and then using the keyboard events that they generate to control your application. It is worth noting that these "virtual keys" are mapped to the screen position rather than room position and so the x/y values are absolute, based on the display size. 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.

NOTE: These functions will not work on the Windows, Ubuntu (Linux), nor the MacOS, target platforms using a touch screen, although they will recieve mouse clicks as "touches".

The available virtual key functions are:

 

 

If you require text or numeric input in your game on a touchscreen device, then you can use the virtual keyboard functions provided to use the device OS keyboard. These functions will call up or hide the OS keyboard and accept input from it, however it will not trigger the regular keyboard events, but rather update the keyboard_string variable with the user input (this is due to the fact that the virtual keyboard can input whole words and not just single characters).

Opening or closing the virtual keyboard will generate System Asynchronous Events, in which the async_load DS map will be populated with the following key/value pairs:

The available virtual keyboard functions are:

NOTE: These functions are only valid for the Android (including AndroidTV), iOS (including tvOS), and UWP target platforms.