Skip to content

Input

Functions

Process Events

ProcessEvents allows SplashKit to react to user interactions. This procedure checks the current keyboard and mouse states and should be called once within your game loop to check user interaction. Side Effects - Reads user interaction events - Updates keys down, text input, etc.

Usage:

Signatures:

void process_events()

Quit Requested

Checks to see if the user has asked for the application to quit. This value is updated by the Process Events routine. Also see window_close_requested.

Return Type: Boolean

Usage:

Signatures:

bool quit_requested()

Reset Quit

Cancels a quit request, ensuring the quit requested will return false.

Signatures:

void reset_quit()

Any Key Pressed

Checks to see if any key has been pressed since the last time Process Events was called.

Return Type: Boolean

Usage:

Signatures:

bool any_key_pressed()

Deregister Callback On Key Down

Remove the registered callback from receiving events related to key down actions.

Parameters:

NameTypeDescription
callbackKey CallbackThe function to from from key down events

Signatures:

void deregister_callback_on_key_down(key_callback *callback)

Deregister Callback On Key Typed

Remove the registered callback from receiving events related to key typed actions.

Parameters:

NameTypeDescription
callbackKey CallbackThe function to from from key typed events

Signatures:

void deregister_callback_on_key_typed(key_callback *callback)

Deregister Callback On Key Up

Remove the registered callback from receiving events related to key up actions.

Parameters:

NameTypeDescription
callbackKey CallbackThe function to from from key up events

Signatures:

void deregister_callback_on_key_up(key_callback *callback)

Key Down

Returns true when the key requested is being held down. This is updated as part of the Process Events call. Use the key codes from Key Code to specify the key to be checked.

Parameters:

NameTypeDescription
keyKey CodeThe key to check if it is down

Return Type: Boolean

Usage:

Signatures:

bool key_down(key_code key)

Key Name

The Key Name function returns a string name for a given Key Code. For example, COMMA_KEY returns the string ‘Comma’. This function could be used to display more meaningful key names for configuring game controls, etc.

Parameters:

NameTypeDescription
keyKey CodeThe key to get the name of

Return Type: String

Signatures:

string key_name(key_code key)

Key Released

Returns true if the specified key was released since the last time Process Events was called. This occurs only once for the key that is released and will not return true again until the key is pressed down and released again.

Parameters:

NameTypeDescription
keyKey CodeThe key to check if it was released

Return Type: Boolean

Signatures:

bool key_released(key_code key)

Key Typed

Returns true when the key requested is just pressed down. This is updated as part of the Process Events call. Use the key codes from Key Code to specify the key to be checked. this will only occur once for that key that is pressed and will not return true again until the key is released and presssed down again

Parameters:

NameTypeDescription
keyKey CodeThe key to check if it was typed

Return Type: Boolean

Usage:

Signatures:

bool key_typed(key_code key)

Key Up

Returns false when the key requested is being held down. This is updated as part of the Process Events call. Use the key codes from Key Code to specify the key to be checked.

Parameters:

NameTypeDescription
keyKey CodeThe key to check if it is up

Return Type: Boolean

Signatures:

bool key_up(key_code key)

Register Callback On Key Down

Register the passed in callback function to receive notification of key down calls. This will be called in response to Process Events, for each key that the user presses down.

Parameters:

NameTypeDescription
callbackKey CallbackThe function to be called when a key is first pressed

Signatures:

void register_callback_on_key_down(key_callback *callback)

Register Callback On Key Typed

Register the passed in callback function to receive notification of key typed calls. This will be called in response to Process Events, when the user initially presses a key down.

Parameters:

NameTypeDescription
callbackKey CallbackThe function to be called when a key is typed

Signatures:

void register_callback_on_key_typed(key_callback *callback)

Register Callback On Key Up

Register the passed in callback function to receive notification of key up calls. This will be called in response to Process Events, for each key that the user releases.

Parameters:

NameTypeDescription
callbackKey CallbackThe function to be called when a key is released

Signatures:

void register_callback_on_key_up(key_callback *callback)

Hide Mouse

Tells the mouse cursor to hide (no longer visible) if it is currently showing. Use ShowMouse to make the mouse cursor visible again.

Signatures:

void hide_mouse()

Mouse Clicked

Returns true if the specified button was clicked since the last time Process Events was called.

Parameters:

NameTypeDescription
buttonMouse ButtonThe mouse button to check

Return Type: Boolean

Usage:

Signatures:

bool mouse_clicked(mouse_button button)

Mouse Down

Returns true if the specified button is currently pressed down.

Parameters:

NameTypeDescription
buttonMouse ButtonThe mouse button to check

Return Type: Boolean

Usage:

Signatures:

bool mouse_down(mouse_button button)

Mouse Movement

Returns the amount of accumulated mouse movement, since the last time Process Events was called, as a Vector 2d.

Return Type: Vector 2d

Usage:

Signatures:

vector_2d mouse_movement()

Mouse Position

Returns the current window position of the mouse as a Point2D

Return Type: Point 2d

Signatures:

point_2d mouse_position()

Mouse Position Vector

Returns The current window position of the mouse as a Vector

Return Type: Vector 2d

Signatures:

vector_2d mouse_position_vector()

Mouse Shown

Returns true if the mouse is currently visible, false if not.

Return Type: Boolean

Signatures:

bool mouse_shown()

Mouse Up

Returns true if the specified button is currently up.

Parameters:

NameTypeDescription
buttonMouse ButtonThe mouse button to check

Return Type: Boolean

Usage:

Signatures:

bool mouse_up(mouse_button button)

Mouse Wheel Scroll

Returns the amount the mouse wheel was scrolled since the last call to Process Events. The result is a vector containing the x and y amounts scrolled. Scroll left generates a negative x, scroll right a positive x. Scroll backward is negative y, scroll forward positive y. Note that on MacOS the directions may be inverted by OS settings.

Return Type: Vector 2d

Signatures:

vector_2d mouse_wheel_scroll()

Mouse X

Returns the current x value of the mouse’s position.

Return Type: Float

Signatures:

float mouse_x()

Mouse Y

Returns the current y value of the mouse’s position.

Return Type: Float

Signatures:

float mouse_y()

Move Mouse

Move Mouse

Moves the mouse cursor to the specified screen location.

Parameters:

NameTypeDescription
xDoubleThe new x location of the mouse
yDoubleThe new y location of the mouse

Signatures:

void move_mouse(double x, double y)

Move Mouse

Moves the mouse cursor to the specified screen location.

Parameters:

NameTypeDescription
pointPoint 2dThe new location of the mouse

Signatures:

void move_mouse(point_2d point)

Show Mouse

Show Mouse

Tells the mouse cursor to be visible if it was previously hidden with by a HideMouse or SetMouseVisible(False) call.

Signatures:

void show_mouse()

Show Mouse

Used to explicitly set the mouse cursors visible state (if it is showing in the window or not) based on the show parameter.

Parameters:

NameTypeDescription
showBooleanWhen true the mouse is shown, when false it is hidden

Signatures:

void show_mouse(bool show)

Draw Collected Text

Draw the text that the user is currently enterring on the current window.

Parameters:

NameTypeDescription
clrColorThe color for the text
fntFontThe font to use
font_sizeIntegerThe size of the font
optsDrawing OptionsAny drawing options

Usage:

Signatures:

void draw_collected_text(color clr, font fnt, int font_size, const drawing_options &opts)

End Reading Text

End Reading Text

Ends reading text in for the current window.

Signatures:

void end_reading_text()

End Reading Text

Ends reading text for the passed in window.

Parameters:

NameTypeDescription
windWindowThe window to end reading text

Signatures:

void end_reading_text(window wind)

Reading Text

Reading Text

Returns true when the current window is reading text.

Return Type: Boolean

Usage:

Signatures:

bool reading_text()

Reading Text

Returns true when the window is reading text.

Parameters:

NameTypeDescription
windWindowThe window to check

Return Type: Boolean

Signatures:

bool reading_text(window wind)

Start Reading Text

Start Reading Text

Start reading text in the current window within the bounds of the supplied rectangle.

Parameters:

NameTypeDescription
rectRectangleThe area where the text will be entered.

Usage:

Signatures:

void start_reading_text(rectangle rect)

Start Reading Text

Start reading text in the current window within the bounds of the supplied rectangle. The text will start with an initial value.

Parameters:

NameTypeDescription
rectRectangleThe area where the text will be entered.
initial_textStringThe initial text, which may be edited by the user.

Signatures:

void start_reading_text(rectangle rect, string initial_text)

Start Reading Text

Start reading text in the window within the bounds of the supplied rectangle.

Parameters:

NameTypeDescription
windWindowThe window where the text will be entered
rectRectangleThe area where the text will be entered.

Signatures:

void start_reading_text(window wind, rectangle rect)

Start Reading Text

Start reading text in the window within the bounds of the supplied rectangle. The text will start with an initial value.

Parameters:

NameTypeDescription
windWindowThe window where the text will be entered
rectRectangleThe area where the text will be entered.
initial_textStringThe initial text, which may be edited by the user.

Signatures:

void start_reading_text(window wind, rectangle rect, string initial_text)

Text Entry Cancelled

Text Entry Cancelled

Did the user press escape and cancel the enterring of text?

Return Type: Boolean

Usage:

Signatures:

bool text_entry_cancelled()

Text Entry Cancelled

Did the user press escape and cancel the enterring of text?

Parameters:

NameTypeDescription
windWindowThe window to check

Return Type: Boolean

Signatures:

bool text_entry_cancelled(window wind)

Text Input

Text Input

The text the user has currently enterred on the current window.

Return Type: String

Usage:

Signatures:

string text_input()

Text Input

The text the user has currently enterred on the current window.

Parameters:

NameTypeDescription
windWindowThe window to check

Return Type: String

Signatures:

string text_input(window wind)

Types

Key Callback

The Key Callback is a function pointer used to register your code with SplashKit or keyboard related events. See Register Callback On Key Down, Register Callback On Key Up, and Register Callback On Key Typed


Key Code

ConstantDescription
UNKNOWN_KEYThe unknown key
BACKSPACE_KEYThe backspace key
TAB_KEYThe tab key
CLEAR_KEYThe clear key
RETURN_KEYThe return key
PAUSE_KEYThe pause key
ESCAPE_KEYThe escape key
SPACE_KEYThe space key
EXCLAIM_KEYThe exclaim key
DOUBLE_QUOTE_KEYThe double quote key
HASH_KEYThe hash key
DOLLAR_KEYThe dollar key
AMPERSAND_KEYThe ampersand key
QUOTE_KEYThe quote key
LEFT_PAREN_KEYThe left paren key
RIGHT_PAREN_KEYThe right paren key
ASTERISK_KEYThe asterisk key
PLUS_KEYThe plus key
COMMA_KEYThe comma key
MINUS_KEYThe minus key
PERIOD_KEYThe period key
SLASH_KEYThe slash key
NUM_0_KEYThe num 0 key
NUM_1_KEYThe num 1 key
NUM_2_KEYThe num 2 key
NUM_3_KEYThe num 3 key
NUM_4_KEYThe num 4 key
NUM_5_KEYThe num 5 key
NUM_6_KEYThe num 6 key
NUM_7_KEYThe num 7 key
NUM_8_KEYThe num 8 key
NUM_9_KEYThe num 9 key
COLON_KEYThe colon key
SEMI_COLON_KEYThe semi colon key
LESS_KEYThe less key
EQUALS_KEYThe equals key
GREATER_KEYThe greater key
QUESTION_KEYThe question key
AT_KEYThe at key
LEFT_BRACKET_KEYThe left bracket key
BACKSLASH_KEYThe backslash () key
RIGHT_BRACKET_KEYThe right bracket key
CARET_KEYThe caret (^) key
UNDERSCORE_KEYThe underscore (_) key
BACKQUOTE_KEYThe backquote (`) key
A_KEYThe a key
B_KEYThe b key
C_KEYThe c key
D_KEYThe d key
E_KEYThe e key
F_KEYThe f key
G_KEYThe g key
H_KEYThe h key
I_KEYThe i key
J_KEYThe j key
K_KEYThe k key
L_KEYThe l key
M_KEYThe m key
N_KEYThe n key
O_KEYThe o key
P_KEYThe p key
Q_KEYThe q key
R_KEYThe r key
S_KEYThe s key
T_KEYThe t key
U_KEYThe u key
V_KEYThe v key
W_KEYThe w key
X_KEYThe x key
Y_KEYThe y key
Z_KEYThe z key
DELETE_KEYThe delete key
KEYPAD_0The keypad 0 key
KEYPAD_1The keypad 1 key
KEYPAD_2The keypad 2 key
KEYPAD_3The keypad 3 key
KEYPAD_4The keypad 4 key
KEYPAD_5The keypad 5 key
KEYPAD_6The keypad 6 key
KEYPAD_7The keypad 7 key
KEYPAD_8The keypad 8 key
KEYPAD_9The keypad 9 key
KEYPAD_PERIODThe keypad period key
KEYPAD_DIVIDEThe keypad divide key
KEYPAD_MULTIPLYThe keypad multiply key
KEYPAD_MINUSThe keypad minus key
KEYPAD_PLUSThe keypad plus key
KEYPAD_ENTERThe keypad enter key
KEYPAD_EQUALSThe keypad equals key
UP_KEYThe up key
DOWN_KEYThe down key
RIGHT_KEYThe right key
LEFT_KEYThe left key
INSERT_KEYThe insert key
HOME_KEYThe home key
END_KEYThe end key
PAGE_UP_KEYThe page up key
PAGE_DOWN_KEYThe page down key
F1_KEYThe f1 key
F2_KEYThe f2 key
F3_KEYThe f3 key
F4_KEYThe f4 key
F5_KEYThe f5 key
F6_KEYThe f6 key
F7_KEYThe f7 key
F8_KEYThe f8 key
F9_KEYThe f9 key
F10_KEYThe f10 key
F11_KEYThe f11 key
F12_KEYThe f12 key
F13_KEYThe f13 key
F14_KEYThe f14 key
F15_KEYThe f15 key
NUM_LOCK_KEYThe num lock key
CAPS_LOCK_KEYThe caps lock key
SCROLL_LOCK_KEYThe scroll lock key
RIGHT_SHIFT_KEYThe right shift key
LEFT_SHIFT_KEYThe left shift key
RIGHT_CTRL_KEYThe right ctrl key
LEFT_CTRL_KEYThe left ctrl key
RIGHT_ALT_KEYThe right alt or option key
LEFT_ALT_KEYThe left alt or option key
LEFT_SUPER_KEYThe left super (windows or command) key
RIGHT_SUPER_KEYThe right super (windows or command) key
MODE_KEYThe mode key
HELP_KEYThe help key
SYS_REQ_KEYThe sys req key
MENU_KEYThe menu key
POWER_KEYThe power key

These are the key codes you can use to check details of keyboard actions. See Key Down, Key Up, Key Typed, and Key Released functions. You can get a string representation of these keys using Key Name.


Mouse Button

ConstantDescription
NO_BUTTONNo mouse button
LEFT_BUTTONThe left mouse button
MIDDLE_BUTTONThe middle mouse button
RIGHT_BUTTONThe right mouse button
MOUSE_X1_BUTTONThe x1 mouse button
MOUSE_X2_BUTTONThe x2 mouse button

A mouse can have many different types of buttons. Most people know about the simple Left and Right buttons, but there is also a Middle button (sometimes part of a scoll wheel), and possible side buttons.