< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_input library

Description

gh_input is the module that manages user's input: mouse, keyboard...


Number of functions: 16

  1. gh_input.joystick_init_di ()
  2. gh_input.joystick_terminate_di ()
  3. gh_input.joystick_poll_di ()
  4. gh_input.joystick_get_button_state ()
  5. gh_input.joystick_get_num ()
  6. gh_input.joystick_get_position ()
  7. gh_input.joystick_get_status ()
  8. gh_input.keyboard_clear_key_buffer ()
  9. gh_input.keyboard_is_key_down ()
  10. gh_input.keyboard_update_buffer ()
  11. gh_input.mouse_get_button_state ()
  12. gh_input.mouse_get_position ()
  13. gh_input.mouse_get_wheel_delta ()
  14. gh_input.mouse_reset_wheel_delta ()
  15. gh_input.mouse_set_position ()
  16. gh_input.mouse_show_cursor ()



joystick_init_di

Description

Initializes the joystick using DirectInput (Windows only).


Syntax

status = gh_input.joystick_init_di()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


-- INIT script			
status = gh_input.joystick_init_di()
			


joystick_terminate_di

Description

Terminates and frees resources used by joystick (Windows only).


Syntax

status = gh_input.joystick_terminate_di()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


-- TERMINATE script						
status = gh_input.joystick_terminate_di()
			


joystick_poll_di

Description

Polls the joystick state. (Windows only).


Syntax

status = gh_input.joystick_poll_di()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


-- FRAME script
gh_input.joystick_poll_di()

posx, posy, posz = gh_input.joystick_get_position(0)

for i=1, 32 do
  buttons[i] = gh_input.joystick_get_button_state(0, i-1)
end
			


joystick_get_button_state

Description

Gets the status of a particular button of a joystick - only four buttons are supported (Windows only).


Syntax

status = gh_input.joystick_get_button_state(
 joy_index,
 button_index
)

Languages


Parameters


Return Values


Code sample


status = gh_input.joystick_get_button_state(joy_index, button_index)
			


joystick_get_num

Description

Returns the number of joysticks supported (Windows only).


Syntax

num_joysticks = gh_input.joystick_get_num()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


num_joys = gh_input.joystick_get_num()
			


joystick_get_position

Description

Gets the position of a joystick along X, Y and Z axis (Windows only).


Syntax

x, y, z = gh_input.joystick_get_position(
 joy_index
)

Languages


Parameters


Return Values


Code sample


x, y, z = gh_input.joystick_get_position(joy_index)
			


joystick_get_status

Description

Gets the status of a particular joystick - only two joysticks are supported (Windows only).


Syntax

status = gh_input.joystick_get_status(
 joy_index
)

Languages


Parameters


Return Values


Code sample


status = gh_input.joystick_get_status(joy_index)
			


keyboard_clear_key_buffer

Description

Clears the keyboard buffer. Call this function once per frame (Windows only).


Syntax

gh_input.keyboard_clear_key_buffer()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_input.keyboard_clear_key_buffer()
			


keyboard_is_key_down

Description

Returns the pressed state of a keyboard key.


Syntax

state = gh_input.keyboard_is_key_down(
 key
)

Languages


Parameters


Return Values


Code sample


-- More key codes can be found in GeeXLab forum.
local KC_W = 17
local KC_S = 31
local KC_A = 30
local KC_D = 32
local KC_LEFT = 75
local KC_RIGHT = 77
local KC_UP = 72
local KC_DOWN = 80
local KC_SPACE = 57

local is_down = gh_input.keyboard_is_key_down(KC_SPACE)
if (is_down == 1) then
    -- pressed!
end
			


keyboard_update_buffer

Description

Updates the keyboard buffer. Call this function before keyboard_is_key_down() (Windows only).


Syntax

gh_input.keyboard_update_buffer()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_input.keyboard_update_buffer()

local is_down = gh_input.keyboard_is_key_down(KC_SPACE)
			


mouse_get_button_state

Description

Returns the state of a mouse button.


Syntax

state = gh_input.mouse_get_button_state(
 button
)

Languages


Parameters


Return Values


Code sample


local LEFT_BUTTON = 1
local RIGHT_BUTTON = 2

local is_down = gh_input.mouse_get_button_state(LEFT_BUTTON)
			


mouse_get_position

Description

Returns the position of the mouse cursor in screen coordinates. The top-left position is the {0, 0} position.


Syntax

x, y = gh_input.mouse_get_position()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


mx, my = gh_input.mouse_get_position()
			


mouse_get_wheel_delta

Description

Returns the delta of the mouse wheel.


Syntax

delta = gh_input.mouse_get_wheel_delta()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


delta = gh_input.mouse_get_wheel_delta()
			


mouse_reset_wheel_delta

Description

Reset the delta value of the mouse wheel.


Syntax

gh_input.mouse_reset_wheel_delta()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_input.mouse_reset_wheel_delta()
			


mouse_set_position

Description

Sets the position of the mouse cursor.


Syntax

gh_input.mouse_set_position(
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_input.mouse_set_position(x, y)
			


mouse_show_cursor

Description

Shows or hide the mouse cursor (Windows only).


Syntax

gh_input.mouse_show_cursor(
 state
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_input.mouse_show_cursor(0)
			






GeeXLab Rootard Guide | Downloads | Contact