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

Device command functions. More...

#include <stdbool.h>

Go to the source code of this file.

Functions

bool * Device_getKeyboardKeysPressed ()
 Gets the current keys being pressed.
char Device_fromKeyCode (int keyCode)
 Converts a key code to a character.
bool * 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.

Deprecated
Non-functional under the ncurses backend; always returns 0. The character is provided directly on CMDFX_EVENT_KEY events (CmdFX_KeyEvent).
Parameters
keyCodeThe key code to convert.
Returns
The character representation of the key code.

◆ Device_getKeyboardKeysPressed()

bool * Device_getKeyboardKeysPressed ( )

Gets the current keys being pressed.

Deprecated
Non-functional under the ncurses backend: terminals cannot report which keys are currently held. This now always reports no keys. Listen for key input through the event system (CMDFX_EVENT_KEY) instead.

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, this method requires administrator privileges.

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

◆ Device_getMouseButtonsPressed()

bool * Device_getMouseButtonsPressed ( )

Gets the current mouse button being pressed.

Deprecated
Non-functional under the ncurses backend: terminals cannot report which buttons are currently held. This now always reports no buttons. Listen for mouse input through the event system (CMDFX_EVENT_MOUSE) instead.

This is a non-blocking method. This method gets the current mouse event. If no mouse button is being pressed, all buttons will be 0.

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.