naev 0.11.5
input.c File Reference

Handles all the keybindings and input. More...

#include "input.h"
#include "array.h"
#include "board.h"
#include "camera.h"
#include "conf.h"
#include "console.h"
#include "escort.h"
#include "gui.h"
#include "hook.h"
#include "info.h"
#include "land.h"
#include "log.h"
#include "map.h"
#include "map_overlay.h"
#include "menu.h"
#include "nstring.h"
#include "pause.h"
#include "pilot.h"
#include "player.h"
#include "toolkit.h"
#include "weapon.h"
#include "utf8.h"

Go to the source code of this file.

Data Structures

struct  Keybind
 Naev Keybinding. More...
 

Macros

#define KEY(s)
 
#define INGAME()
 
#define NOHYP()
 
#define NODEAD()
 
#define NOLAND()
 

Functions

static void input_key (int keynum, double value, double kabs, int repeat)
 Runs the input command.
 
static void input_clickZoom (double modifier)
 Handles zoom.
 
static void input_clickevent (SDL_Event *event)
 Handles a click event.
 
static void input_mouseMove (SDL_Event *event)
 Provides mouse X and Y coordinates for mouse flying.
 
void input_setDefault (int wasd)
 Sets the default input keys.
 
void input_init (void)
 Initializes the input subsystem (does not set keys).
 
void input_exit (void)
 exits the input subsystem.
 
void input_enableAll (void)
 Enables all the keybinds.
 
void input_disableAll (void)
 Disables all the keybinds.
 
void input_toggleEnable (const char *key, int enable)
 Enables or disables a keybind.
 
void input_mouseShow (void)
 Shows the mouse.
 
void input_mouseHide (void)
 Hides the mouse.
 
SDL_Keycode input_keyConv (const char *name)
 Gets the key id from its name.
 
void input_setKeybind (const char *keybind, KeybindType type, SDL_Keycode key, SDL_Keymod mod)
 Binds key of type type to action keybind.
 
SDL_Keycode input_getKeybind (const char *keybind, KeybindType *type, SDL_Keymod *mod)
 Gets the value of a keybind.
 
void input_getKeybindDisplay (const char *keybind, char *buf, int len)
 Gets the display name (translated and human-readable) of a keybind.
 
const char * input_modToText (SDL_Keymod mod)
 Gets the human readable version of mod.
 
const char * input_keyAlreadyBound (KeybindType type, SDL_Keycode key, SDL_Keymod mod)
 Checks to see if a key is already bound.
 
const char * input_getKeybindDescription (const char *keybind)
 Gets the description of the keybinding.
 
SDL_Keymod input_translateMod (SDL_Keymod mod)
 Translates SDL modifier to Naev modifier.
 
void input_update (double dt)
 Handles key repeating.
 
static void input_joyaxis (const SDL_Keycode axis, const int value)
 Filters a joystick axis event.
 
static void input_joyevent (const int event, const SDL_Keycode button)
 Filters a joystick button event.
 
static void input_keyevent (const int event, SDL_Keycode key, const SDL_Keymod mod, const int repeat)
 Filters a keyboard event.
 
static void input_joyhatevent (const Uint8 value, const Uint8 hat)
 Filters a joystick hat event.
 
int input_clickPos (SDL_Event *event, double x, double y, double zoom, double minpr, double minr)
 Handles a click at a position in the current system.
 
int input_clickedJump (int jump, int autonav)
 Performs an appropriate action when a jump point is clicked.
 
int input_clickedSpob (int spob, int autonav)
 Performs an appropriate action when a spob is clicked.
 
int input_clickedAsteroid (int field, int asteroid)
 Performs an appropriate action when an asteroid is clicked.
 
int input_clickedPilot (unsigned int pilot, int autonav)
 Performs an appropriate action when a pilot is clicked.
 
void input_clicked (void *clicked)
 Sets the last-clicked item, for double-click detection.
 
int input_isDoubleClick (void *clicked)
 Checks whether a clicked item is the same as the last-clicked.
 
void input_handle (SDL_Event *event)
 Handles global input.
 

Variables

const char * keybind_info [][3]
 
static Keybindinput_keybinds
 
const int input_numbinds = ( sizeof( keybind_info ) / sizeof( keybind_info[ 0 ] ) ) - 1
 
static Keybindinput_paste
 
static int doubletap_key = -1
 
static unsigned int doubletap_t = 0
 
static int repeat_key = -1
 
static unsigned int repeat_keyTimer = 0
 
static unsigned int repeat_keyCounter = 0
 
static double input_mouseTimer = 1.
 
static int input_mouseCounter = 1
 
static unsigned int input_mouseClickLast = 0
 
static void * input_lastClicked = NULL
 
double player_left
 
double player_right
 

Detailed Description

Handles all the keybindings and input.

Definition in file input.c.

Macro Definition Documentation

◆ INGAME

#define INGAME ( )
Value:
(!toolkit_isOpen() && ((value==KEY_RELEASE) || !player_isFlag(PLAYER_CINEMATICS)))
int toolkit_isOpen(void)
Checks to see if the toolkit is open.
Definition toolkit.c:94

Makes sure player is in game.

Definition at line 646 of file input.c.

◆ KEY

#define KEY ( s)
Value:
(strcmp(input_keybinds[keynum].name,s)==0)
static Keybind * input_keybinds
Definition input.c:128

Shortcut for ease.

Definition at line 645 of file input.c.

◆ NODEAD

#define NODEAD ( )
Value:
((player.p != NULL) && !pilot_isFlag(player.p,PILOT_DEAD))
Player_t player
Definition player.c:74
Pilot * p
Definition player.h:101

Player isn't dead.

Definition at line 651 of file input.c.

◆ NOHYP

#define NOHYP ( )
Value:
((player.p != NULL) && !pilot_isFlag(player.p,PILOT_HYP_PREP) &&\
!pilot_isFlag(player.p,PILOT_HYP_BEGIN) &&\
!pilot_isFlag(player.p,PILOT_HYPERSPACE))

Make sure the player isn't jumping.

Definition at line 647 of file input.c.

◆ NOLAND

#define NOLAND ( )
Value:
((player.p != NULL) && (!landed && !pilot_isFlag(player.p,PILOT_LANDING)))
int landed
Definition land.c:75

Player isn't landed.

Definition at line 652 of file input.c.

Function Documentation

◆ input_clicked()

void input_clicked ( void * clicked)

Sets the last-clicked item, for double-click detection.

Parameters
clickedPointer to the clicked item.

Definition at line 1449 of file input.c.

◆ input_clickedAsteroid()

int input_clickedAsteroid ( int field,
int asteroid )

Performs an appropriate action when an asteroid is clicked.

Parameters
fieldIndex of the parent field of the asteoid.
asteroidIndex of the oasteoid in the field.
Returns
Whether the click was used.

Definition at line 1400 of file input.c.

◆ input_clickedJump()

int input_clickedJump ( int jump,
int autonav )

Performs an appropriate action when a jump point is clicked.

Parameters
jumpIndex of the jump point.
autonavWhether to autonav to the target.
Returns
Whether the click was used.

Definition at line 1322 of file input.c.

◆ input_clickedPilot()

int input_clickedPilot ( unsigned int pilot,
int autonav )

Performs an appropriate action when a pilot is clicked.

Parameters
pilotIndex of the pilot.
autonavWhether this is an autonav action.
Returns
Whether the click was used.

Definition at line 1416 of file input.c.

◆ input_clickedSpob()

int input_clickedSpob ( int spob,
int autonav )

Performs an appropriate action when a spob is clicked.

Parameters
spobIndex of the spob.
autonavWhether to autonav to the target.
Returns
Whether the click was used.

Definition at line 1357 of file input.c.

◆ input_clickevent()

static void input_clickevent ( SDL_Event * event)
static

Handles a click event.

Definition at line 1171 of file input.c.

◆ input_clickPos()

int input_clickPos ( SDL_Event * event,
double x,
double y,
double zoom,
double minpr,
double minr )

Handles a click at a position in the current system.

event The click event itself, used for button information.

x X coordinate within the system.

y Y coordinate within the system.

zoom Camera zoom (mostly for on-screen targeting).

minpr Minimum radius to assign to pilots.

minr Minimum radius to assign to spobs and jumps.

Returns
Whether the click was used to trigger an action.

Definition at line 1234 of file input.c.

◆ input_clickZoom()

static void input_clickZoom ( double modifier)
static

Handles zoom.

Definition at line 1151 of file input.c.

◆ input_disableAll()

void input_disableAll ( void )

Disables all the keybinds.

Definition at line 346 of file input.c.

◆ input_enableAll()

void input_enableAll ( void )

Enables all the keybinds.

Definition at line 337 of file input.c.

◆ input_exit()

void input_exit ( void )

exits the input subsystem.

Definition at line 329 of file input.c.

◆ input_getKeybind()

SDL_Keycode input_getKeybind ( const char * keybind,
KeybindType * type,
SDL_Keymod * mod )

Gets the value of a keybind.

Parameters
[in]keybindName of the keybinding to get.
[out]typeStores the type of the keybinding.
[out]modStores the modifiers used with the keybinding.
Returns
The key associated with the keybinding.

Definition at line 431 of file input.c.

◆ input_getKeybindDescription()

const char * input_getKeybindDescription ( const char * keybind)

Gets the description of the keybinding.

Parameters
keybindKeybinding to get the description of.
Returns
Description of the keybinding.

Definition at line 582 of file input.c.

◆ input_getKeybindDisplay()

void input_getKeybindDisplay ( const char * keybind,
char * buf,
int len )

Gets the display name (translated and human-readable) of a keybind.

Parameters
[in]keybindName of the keybinding to get display name of.
[out]bufBuffer to write the display name to.
[in]lenLength of buffer.

Definition at line 453 of file input.c.

◆ input_handle()

void input_handle ( SDL_Event * event)

Handles global input.

Basically separates the event types

Parameters
eventIncoming SDL_Event.

Definition at line 1485 of file input.c.

◆ input_init()

void input_init ( void )

Initializes the input subsystem (does not set keys).

Definition at line 278 of file input.c.

◆ input_isDoubleClick()

int input_isDoubleClick ( void * clicked)

Checks whether a clicked item is the same as the last-clicked.

Parameters
clickedPointer to the clicked item.

Definition at line 1462 of file input.c.

◆ input_joyaxis()

static void input_joyaxis ( const SDL_Keycode axis,
const int value )
static

Filters a joystick axis event.

Parameters
axisAxis generated by the event.
valueValue of the axis.

Definition at line 1049 of file input.c.

◆ input_joyevent()

static void input_joyevent ( const int event,
const SDL_Keycode button )
static

Filters a joystick button event.

Parameters
eventEvent type (down/up).
buttonButton generating the event.

Definition at line 1078 of file input.c.

◆ input_joyhatevent()

static void input_joyhatevent ( const Uint8 value,
const Uint8 hat )
static

Filters a joystick hat event.

Parameters
valueDirection on hat.
hatHat generating the event.

Definition at line 1094 of file input.c.

◆ input_key()

static void input_key ( int keynum,
double value,
double kabs,
int repeat )
static

Runs the input command.

Parameters
keynumThe index of the keybind.
valueThe value of the keypress (defined above).
kabsThe absolute value.
repeatWhether the key is still held down, rather than newly pressed.

Definition at line 661 of file input.c.

◆ input_keyAlreadyBound()

const char * input_keyAlreadyBound ( KeybindType type,
SDL_Keycode key,
SDL_Keymod mod )

Checks to see if a key is already bound.

Parameters
typeType of key.
keyKey.
modKey modifiers.
Returns
Name of the key that is already bound to it.

Definition at line 537 of file input.c.

◆ input_keyConv()

SDL_Keycode input_keyConv ( const char * name)

Gets the key id from its name.

Parameters
nameName of the key to get id from.
Returns
ID of the key.

Definition at line 392 of file input.c.

◆ input_keyevent()

static void input_keyevent ( const int event,
SDL_Keycode key,
const SDL_Keymod mod,
const int repeat )
static

Filters a keyboard event.

Parameters
eventEvent type (down/up).
keyKey generating the event.
modModifiers active when event was generated.
repeatWhether the key is still held down, rather than newly pressed.

< Release always gets through.

Definition at line 1130 of file input.c.

◆ input_modToText()

const char * input_modToText ( SDL_Keymod mod)

Gets the human readable version of mod.

Parameters
modMod to get human readable version from.
Returns
Human readable version of mod.

Definition at line 516 of file input.c.

◆ input_mouseHide()

void input_mouseHide ( void )

Hides the mouse.

Definition at line 377 of file input.c.

◆ input_mouseMove()

static void input_mouseMove ( SDL_Event * event)
static

Provides mouse X and Y coordinates for mouse flying.

Definition at line 1160 of file input.c.

◆ input_mouseShow()

void input_mouseShow ( void )

Shows the mouse.

Definition at line 368 of file input.c.

◆ input_setDefault()

void input_setDefault ( int wasd)

Sets the default input keys.

Parameters
wasdWhether to use the WASD layout.

Definition at line 172 of file input.c.

◆ input_setKeybind()

void input_setKeybind ( const char * keybind,
KeybindType type,
SDL_Keycode key,
SDL_Keymod mod )

Binds key of type type to action keybind.

Parameters
keybindThe name of the keybind defined above.
typeThe type of the keybind.
keyThe key to bind to.
modModifiers to check for.

Definition at line 409 of file input.c.

◆ input_toggleEnable()

void input_toggleEnable ( const char * key,
int enable )

Enables or disables a keybind.

Definition at line 355 of file input.c.

◆ input_translateMod()

SDL_Keymod input_translateMod ( SDL_Keymod mod)

Translates SDL modifier to Naev modifier.

Parameters
modSDL modifier to translate.
Returns
Naev modifier.

Definition at line 597 of file input.c.

◆ input_update()

void input_update ( double dt)

Handles key repeating.

Definition at line 614 of file input.c.

Variable Documentation

◆ doubletap_key

int doubletap_key = -1
static

Last key double tapped.

Definition at line 135 of file input.c.

◆ doubletap_t

unsigned int doubletap_t = 0
static

Used to see if double tap accel.

Definition at line 136 of file input.c.

◆ input_keybinds

Keybind* input_keybinds
static

contains the players keybindings

Definition at line 128 of file input.c.

◆ input_lastClicked

void* input_lastClicked = NULL
static

Pointer to the last-clicked item.

Definition at line 151 of file input.c.

◆ input_mouseClickLast

unsigned int input_mouseClickLast = 0
static

Time of last click (in ms)

Definition at line 150 of file input.c.

◆ input_mouseCounter

int input_mouseCounter = 1
static

Counter for mouse display/hiding.

Definition at line 149 of file input.c.

◆ input_mouseTimer

double input_mouseTimer = 1.
static

Timer for hiding again.

Definition at line 148 of file input.c.

◆ input_numbinds

const int input_numbinds = ( sizeof( keybind_info ) / sizeof( keybind_info[ 0 ] ) ) - 1

Number of keybindings.

Definition at line 129 of file input.c.

◆ input_paste

Keybind* input_paste
static

Definition at line 130 of file input.c.

◆ keybind_info

const char* keybind_info[][3]

Names of possible keybindings.

Definition at line 50 of file input.c.

◆ player_left

double player_left
extern

player.c

Player left turn velocity from input.

Definition at line 121 of file player.c.

◆ player_right

double player_right
extern

player.c

Player right turn velocity from input.

Definition at line 122 of file player.c.

◆ repeat_key

int repeat_key = -1
static

Key to repeat.

Definition at line 141 of file input.c.

◆ repeat_keyCounter

unsigned int repeat_keyCounter = 0
static

Counter for key repeats.

Definition at line 143 of file input.c.

◆ repeat_keyTimer

unsigned int repeat_keyTimer = 0
static

Repeat timer.

Definition at line 142 of file input.c.