cmdfx 0.1.1
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
device.h File Reference

Device command functions. More...

Go to the source code of this file.

Functions

int * Device_getKeyboardKeysPressed ()
 Gets the current keys being pressed.
 
char Device_fromKeyCode (int keyCode)
 Converts a key code to a character.
 
int * Device_getMouseButtonsPressed ()
 Gets the current mouse button being pressed.
 

Detailed Description

Device command functions.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.1.1
Date
2025-02-07

Function Documentation

◆ Device_fromKeyCode()

char Device_fromKeyCode ( int keyCode)

Converts a key code to a character.

Parameters
keyCodeThe key code to convert.
Returns
The character representation of the key code.

◆ Device_getKeyboardKeysPressed()

int * Device_getKeyboardKeysPressed ( )

Gets the current keys being pressed.

The size of the array is always 256, with each index corresponding to a key code native to the operating system. If the key is being pressed, the value at the index will be 1. If the key is not being pressed, the value at the index will be 0.

This is a non-blocking method. This method gets the current key being pressed on the keyboard. If no key is being pressed, it will return -1.

The array must be freed after use.

Preconditions:

On macOS, the application must be added to the "Input Monitoring" permission in the "Security & Privacy" settings. Otherwise, only control keys will be detected.

On Linux, method requires administrator privileges.

Returns
The list of key code of the key being pressed.

◆ Device_getMouseButtonsPressed()

int * Device_getMouseButtonsPressed ( )

Gets the current mouse button being pressed.

This is a non-blocking method. This method gets the current mouse event. If no mouse button is being pressed, it will return -1.

On most systems, the button values are as follows (according to index):

  • 0: Left mouse button
  • 1: Right mouse button
  • 2: Middle mouse button

The array must be freed after use.

This method requires administrator privileges on Linux.

Returns
The list of mouse button code of the button being pressed.