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.

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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.

ConstantValueDescription
UNKNOWN_KEY0The unknown key
BACKSPACE_KEY8The backspace key
TAB_KEY9The tab key
CLEAR_KEY12The clear key
RETURN_KEY13The return key
PAUSE_KEY19The pause key
ESCAPE_KEY27The escape key
SPACE_KEY32The space key
EXCLAIM_KEY33The exclaim key
DOUBLE_QUOTE_KEY34The double quote key
HASH_KEY35The hash key
DOLLAR_KEY36The dollar key
AMPERSAND_KEY38The ampersand key
QUOTE_KEY39The quote key
LEFT_PAREN_KEY40The left paren key
RIGHT_PAREN_KEY41The right paren key
ASTERISK_KEY42The asterisk key
PLUS_KEY43The plus key
COMMA_KEY44The comma key
MINUS_KEY45The minus key
PERIOD_KEY46The period key
SLASH_KEY47The slash key
NUM_0_KEY48The num 0 key
NUM_1_KEY49The num 1 key
NUM_2_KEY50The num 2 key
NUM_3_KEY51The num 3 key
NUM_4_KEY52The num 4 key
NUM_5_KEY53The num 5 key
NUM_6_KEY54The num 6 key
NUM_7_KEY55The num 7 key
NUM_8_KEY56The num 8 key
NUM_9_KEY57The num 9 key
COLON_KEY58The colon key
SEMI_COLON_KEY59The semi colon key
LESS_KEY60The less key
EQUALS_KEY61The equals key
GREATER_KEY62The greater key
QUESTION_KEY63The question key
AT_KEY64The at key
LEFT_BRACKET_KEY91The left bracket key
BACKSLASH_KEY92The backslash () key
RIGHT_BRACKET_KEY93The right bracket key
CARET_KEY94The caret (^) key
UNDERSCORE_KEY95The underscore (_) key
BACKQUOTE_KEY96The backquote (`) key
A_KEY97The a key
B_KEY98The b key
C_KEY99The c key
D_KEY100The d key
E_KEY101The e key
F_KEY102The f key
G_KEY103The g key
H_KEY104The h key
I_KEY105The i key
J_KEY106The j key
K_KEY107The k key
L_KEY108The l key
M_KEY109The m key
N_KEY110The n key
O_KEY111The o key
P_KEY112The p key
Q_KEY113The q key
R_KEY114The r key
S_KEY115The s key
T_KEY116The t key
U_KEY117The u key
V_KEY118The v key
W_KEY119The w key
X_KEY120The x key
Y_KEY121The y key
Z_KEY122The z key
DELETE_KEY127The delete key
KEYPAD_0256The keypad 0 key
KEYPAD_1257The keypad 1 key
KEYPAD_2258The keypad 2 key
KEYPAD_3259The keypad 3 key
KEYPAD_4260The keypad 4 key
KEYPAD_5261The keypad 5 key
KEYPAD_6262The keypad 6 key
KEYPAD_7263The keypad 7 key
KEYPAD_8264The keypad 8 key
KEYPAD_9265The keypad 9 key
KEYPAD_PERIOD266The keypad period key
KEYPAD_DIVIDE267The keypad divide key
KEYPAD_MULTIPLY268The keypad multiply key
KEYPAD_MINUS269The keypad minus key
KEYPAD_PLUS270The keypad plus key
KEYPAD_ENTER271The keypad enter key
KEYPAD_EQUALS272The keypad equals key
UP_KEY273The up key
DOWN_KEY274The down key
RIGHT_KEY275The right key
LEFT_KEY276The left key
INSERT_KEY277The insert key
HOME_KEY278The home key
END_KEY279The end key
PAGE_UP_KEY280The page up key
PAGE_DOWN_KEY281The page down key
F1_KEY282The f1 key
F2_KEY283The f2 key
F3_KEY284The f3 key
F4_KEY285The f4 key
F5_KEY286The f5 key
F6_KEY287The f6 key
F7_KEY288The f7 key
F8_KEY289The f8 key
F9_KEY290The f9 key
F10_KEY291The f10 key
F11_KEY292The f11 key
F12_KEY293The f12 key
F13_KEY294The f13 key
F14_KEY295The f14 key
F15_KEY296The f15 key
NUM_LOCK_KEY300The num lock key
CAPS_LOCK_KEY301The caps lock key
SCROLL_LOCK_KEY302The scroll lock key
RIGHT_SHIFT_KEY303The right shift key
LEFT_SHIFT_KEY304The left shift key
RIGHT_CTRL_KEY305The right ctrl key
LEFT_CTRL_KEY306The left ctrl key
RIGHT_ALT_KEY307The right alt or option key
LEFT_ALT_KEY308The left alt or option key
LEFT_SUPER_KEY311The left super (windows or command) key
RIGHT_SUPER_KEY312The right super (windows or command) key
MODE_KEY313The mode key
HELP_KEY315The help key
SYS_REQ_KEY317The sys req key
MENU_KEY319The menu key
POWER_KEY320The 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

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.

ConstantValueDescription
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.