arc.input

Input module allows access to the keyboard and the mouse.

Authors:
ArcLib team, see AUTHORS file

Maintainer:
Clay Smith (clayasaurus at gmail dot com)

License:
zlib/libpng license:

Description:
The input module allows the user access to keyboard, mouse and joystick. Input must be processed once every frame. Use keyPressed methods to tell if user only lightly pressed their key. Use keyDown methods to tell if user is holding a key down. Use keyReleased to tell when user has released a key.

Examples:
    import arc.input;

int main() {

	// initializes input
	arc.input.open();
	arc.input.openJoysticks();

	// while the user hasn't closed the window
	while (!arc.input.keyDown(SDL_QUIT))
	{
		// get current input from user
		arc.input.process();

		// user lightly taps 't' key
		arc.input.keyPressed('t'); // a-z, SDLK_a-SDLK_z

		// user holds down 't' key
		arc.input.keyDown('t');

		// user lightly clicks right mouse button
		arc.input.mouseButtonPressed(RIGHT);

		// user holds down left mouse button
		arc.input.mouseButtonDown(LEFT) // RIGHT and MIDDLE work as well

		// returns true if user hits a character
		if (arc.input.charHit) {
			// returns the last characters the user hit
			char[] ch = arc.input.lastChars;
		}

		// returns position of mouse
		arc.input.mouseX; // .mouseY  .mouseOldY  .mouseOldX

		// returns true if mouse is in motion
		arc.input.mouseMotion;

		// returns true if mouse is wheeling up
		// wheelDown - returns true on mouse Wheelup and Wheeldown
		arc.input.wheelUp;

		// return true if current modifier is down
		// RSHIFT, LCTRL, RCTRL, LALT, RALT, LMETA, RMETA, NUM, CAPS
		arc.input.modHit(LSHIFT);
		arc.input.modDown(LSHIFT);

		foreach(stick; joysticksIter)
		{
			foreach(button; arc.input.joyButtonsDown(stick))
				writefln("button ", button, " pressed on joystick ", stick );
			foreach(button; arc.input.joyButtonsUp(stick))
				writefln("button ", button, " released on joystick ", stick );
			foreach(pos, axis; joyAxesMove(stick))
				writefln("axis ", axis, " moved to ", pos, " on joystick ", stick );
		}


		// close doesn't actually do anything now
        arc.input.close();

        return 0;
    }


void open (bool keyRepeat = true);
clear's input, gets current modifiers, enables unicode and disables key repeat

void close ();
implementation just for symmetry, does not do anything

void setKeyboardRepeat (bool onoff);
sets keyboard repeat on or off

KeyStatus keyStatus (int keyNum);
returns the full KeyStatus information for the key

bool isSet (T)(T state, T flag);
test if is set

bool keyPressed (int keyNum);
returns true when key has gone from up to down between calls to process

bool keyReleased (int keyNum);
returns true when key has gone from down to up between calls to process

bool keyDown (int keyNum);
returns true when key is physically down

bool keyUp (int keyNum);
returns true when key is physically up

bool charHit ();
returns true if user has hit a character on the keyboard between two calls to process

char[] lastChars ();
returns characters hit by the user between two process calls

KeyStatus mouseButtonStatus (int keyNum);
returns full KeyStatus information for the button

bool mouseButtonPressed (int keyNum);
returns true if mouse button has gone from up to down between calls to process

bool mouseButtonReleased (int keyNum);
returns true if mouse button has gone from down to up between calls to process

bool mouseButtonDown (int keyNum);
returns true if user holds mouse button down

bool mouseButtonUp (int keyNum);
returns true if user doesn't hold mouse button down

float mouseX ();
mouseX position

float mouseY ();
mouseY position

Point mousePos ();
mouse position

float mouseOldX ();
old mouse X position

float mouseOldY ();
old mouse Y position

Point mouseOldPos ();
old mouse position

bool mouseMotion ();
returns true when mouse is moving

void defaultCursorVisible (bool argV);
set mouse cursor visibility

bool wheelUp ();
returns true when mouse is wheeling up

bool wheelDown ();
returns true when mouse is wheeling down

class JoystickException : object.Exception;
JoyStick Exception Class

ubyte numJoysticks ();
returns the number of joysticks that are plugged in

int openJoysticks (int index = -1);
Joysticks have to be opened with this function before they can be used. Use numJoysticks() to query the number of sticks (or gamepads) that are plugged in. Joysticks are identified by a number, starting from 0. Either specify a joystick by index to be opened, or call this function without any arguments to open all available joysticks. The number of joysticks that are actually opened is returned.

Use numJoysticks to query the number of sticks or pads that are plugged in.

void closeJoysticks (int index = -1);
The counterpart to openJoysticks.

bool joyButtonDown (ubyte index, ubyte button);
returns whether button is currently down on joystick index (button numbers start from 0)

button must be smaller than numJoystickButtons(index) or a runtime error will result.

bool joyButtonUp (ubyte index, ubyte button);
returns whether button is up, see joyButtonDown for details

bool joyButtonPressed (ubyte index, ubyte button);
returns whether button has been pressed since last call to process

bool joyButtonReleased (ubyte index, ubyte button);
returns whether button has been released since last call to process

float joyAxisMoved (ubyte index, ubyte axis);
returns position of axis on joystick index (axes numbers start from 0) axis must be smaller than numJoystickAxes(index) or a runtime error will result.

The value returned is the current position of the axis, which is in the range of -1.0f to 1.0f epsilon (give or take) An exact value of 0.0f has a special meaning: in this case there was no axis movement at all

int delegate(int delegate(ref ubyte)) joysticksIter ;
iterate over all open joysticks

ButtonIterator joyButtonsDown (ubyte index);
iterate over currently down on joystick index

Throws:
JoystickException if index is not valid

ButtonIterator joyButtonsUp (ubyte index);
iterate over buttons currently up on joystick index

Throws:
JoystickException if index is not valid

ButtonIterator joyButtonsPressed (ubyte index);
iterate over buttons on joystick index that were pressed since last call to process

Throws:
JoystickException if index is not valid

ButtonIterator joyButtonsReleased (ubyte index);
iterate over buttons on joystick index that were released since last call to process

Throws:
JoystickException if index is not valid

int delegate(int delegate(ref ubyte, ref float)) joyAxesMoved (ubyte index);
iterate over axes moved on joystick index since last call to process

ubyte numJoystickButtons (ubyte index);
number of buttons on joystick index or 0 if joystick is not opened

ubyte numJoystickAxes (ubyte index);
number of axes on joystick index or 0 if joystick is not opened

char[] joystickName (ubyte index);
vendor specific string describing this device or empty string if joystick is not opened

bool isJoystickOpen (ubyte index);
true if this joystick has been opened, false otherwise

void setAxisThreshold (float threshold);


bool lostFocus ();
return whether SDL window has lost focus

void quit ();
force quit of application

bool isQuit ();
returns true if quitting

void process ();
Capture input from user

Page was generated with on Mon Jul 16 17:24:02 2007