Skip to content
slaeshjag edited this page Mar 24, 2013 · 5 revisions

DARNIT_KEYACTION

Used by DARNIT_KEY_RAW to specify if it was a press or release event.

typedef enum {
        DARNIT_KEYACTION_PRESS = 1,
        DARNIT_KEYACTION_RELEASE = 2,
} DARNIT_KEYACTION;

DARNIT_KEYS

This struct contains keystatus for all main input keys. 0 means key is not pressed, 1 means the key is pressed.

typedef struct {
        unsigned int    left            : 1;
        unsigned int    right           : 1;
        unsigned int    up              : 1;
        unsigned int    down            : 1;
        unsigned int    x               : 1;
        unsigned int    y               : 1;
        unsigned int    a               : 1;
        unsigned int    b               : 1;
        unsigned int    start           : 1;
        unsigned int    select          : 1;
        unsigned int    l               : 1;
        unsigned int    r               : 1;
        unsigned int    lmb             : 1;    /* Left mouse button */
        unsigned int    rmb             : 1;    /* Right mouse button */
        unsigned int    padding         : 2;    /* Not used for anything */

        /* Modifier keys (SHIFT, CTRL, ALT etc..) */
        unsigned int    mod_lshift      : 1;
        unsigned int    mod_rshift      : 1;
        unsigned int    mod_lctrl       : 1;
        unsigned int    mod_rctrl       : 1;
        unsigned int    mod_lalt        : 1;
        unsigned int    mod_ralt        : 1;
        unsigned int    mod_lmeta       : 1;
        unsigned int    mod_rmeta       : 1;
        unsigned int    mod_num         : 1;
        unsigned int    mod_caps        : 1;
        unsigned int    mod_mode        : 1;
} DARNIT_KEYS;

DARNIT_KEY_RAW

Raw keyboard events. Suitable for text input etc..

typedef struct {
        int                     keysym;
        DARNIT_KEYACTION        action;
        int                     unicode;
} DARNIT_KEY_RAW;

If unicode is enabled, the field unicode contains the unicode representation of the key just pressed. Keysym is just a standard SDL keysym value.

DARNIT_MOUSE

Contains status information about mouse position

typedef struct {
        unsigned int    x       : 16;
        unsigned int    y       : 16;
        signed int      wheel   : 32;
        unsigned int    lmb     : 1;
        unsigned int    rmb     : 1;
} DARNIT_MOUSE;

Note that wheel is relative. It resets every time you request mouse status.

  • x - X coordinate for mouse cursor
  • y - Y coordinate for mouse cursor
  • wheel - Delta value for scroll wheel (negative is up, positive is down)
  • lmb - Left mouse button
  • rmb - Right mouse button

DARNIT_INPUT_MAP

This is the keymapping struct used to remap the main input keys. All values are normal SDL keysyms that maps to the keys. Click here for default key mappings for different systems.

typedef struct {
        unsigned int                    up;
        unsigned int                    down;
        unsigned int                    left;
        unsigned int                    right;
        unsigned int                    x;
        unsigned int                    y;
        unsigned int                    a;
        unsigned int                    b;
        unsigned int                    start;
        unsigned int                    select;
        unsigned int                    l;
        unsigned int                    r;
} DARNIT_INPUT_MAP;

DARNIT_INPUT

Various functions to get status about the supported input devices

d_keys_get

DARNIT_KEYS d_keys_get();

Returns the current status for the main input keys.

Arguments None.

Return value

Returns a DARNIT_KEYS structure containing the current status for all main input keys.

d_keys_set

void d_keys_set(DARNIT_KEYS keys);

All keys marked as 1 will be set as not pressed until they are released and pressed again.

Arguments

A DARNIT_KEYS struct with the keys to mark as not pressed set to 1.

Return value None.

d_keys_zero

DARNIT_KEYS d_keys_zero();

Returns a DARNIT_KEYS struct will all members set to 0.

Arguments None.

Return value A DARNIT_KEYS struct will all keys set to 0.

d_input_grab

void d_input_grab();

Grabs input and prevents focus from leaving the window.

Arguments None.

Return value None.

d_input_release

void d_input_release();

Releases input grab (mouse cursor can now leave the window, you can tab out of the window etc..)

Arguments None.

Return value None.

d_mouse_get

DARNIT_MOUSE d_mouse_get();

Returns a DARNIT_MOUSE struct containing status about the mouse.

Arguments None.

Return value Returns a DARNIT_MOUSE struct containing status about the mouse.

d_keymapping_reset

void d_keymapping_reset();

Resets the main input key mapping to defaults for the platform.

Arguments None.

Return value None.

d_keymapping_set

void d_keymapping_set(DARNIT_INPUT_MAP map);

Sets the main input keymapping according to map.

Arguments

  • map - A struct containing the keysyms that the main input buttons should map to

Return value None.

d_keymapping_get

DARNIT_INPUT_MAP d_keymapping_get();

Returns the current main input keys sym map.

Arguments None.

Return value

Returns the current key input mapping.

d_joystick_get

void d_joystick_get(int *js0_x, int js0_y, int js1_x, int js1_y);

Sets the ints that the arguments points to, to the coordinates of joystick 0 and joystick 1.

Arguments

  • js0_x - The int that this pointer points to is set to joystick 0's X coordinate (-32768..32767)
  • js0_y - The int that this pointer points to is set to joystick 0's Y coordinate (-32768..32767)
  • js1_x - The int that this pointer points to is set to joystick 1's X coordinate (-32768..32767)
  • js1_y - The int that this pointer points to is set to joystick 1's Y coordinate (-32768..32767)

Return value None.

d_key_raw_push

void d_key_raw_push(int sym, DARNIT_KEYACTION action, int unicode);

Pushes a raw keyboard event to the raw keyboard event buffer.

Arguments

  • sym - The SDL keysym to associate with the event
  • action - what kind of event it was (key press or release)
  • unicode - The unicode representation of the event

Return value None.

d_key_raw_pop

DARNIT_KEY_RAW d_key_pop();

Pops a raw keyboard event from the keyboard event buffer.

Argument None.

Return value A DARNIT_KEY_RAW struct describing the keyboard event.

d_key_raw_clear

void d_key_raw_clear();

Discards all waiting raw keyboard events.

Arguments None.

Return value None.

d_input_unicode

void d_input_unicode(int enable)

Enables or disables unicode conversion (populates the unicode field in raw keyboard events.) Enabling this will degrade input performance a bit.

Arguments

  • enable - Set to 1 to enable unicode conversion. Set to 0 to disable

Return value None.

d_key_name_get

const char *d_key_name_get(int sym);

Converts a SDL keysym number to a human-readable string describing the key.

Arguments

sym - A SDL keysym to describe

Return value

A string describing the keysym. Note: The string returned is only valid until this function is called again. The buffer is re-used.

Clone this wiki locally