Module for getting keyboard and mouse input. is* functions return info based on a us QWERTY layout. They are supposed to be used for game controls. For text input use getStr.

Keycode constants

type Key* = enum {
	mouse1         = 1   // NOTE: mouse 2 and 3 key codes are swapped
	mouse2         = 3   //       because sokol uses 3 for middle mouse
	mouse3         = 2   //       button.

	ctrl           = 16
	shift          = 17
	alt            = 18

	space          = 32
	apostrophe     = 39  /* ' */
	comma          = 44  /* , */
	minus          = 45  /* - */
	dot            = 46  /* . */
	slash          = 47  /* / */
	num0           = 48
	num1           = 49
	num2           = 50
	num3           = 51
	num4           = 52
	num5           = 53
	num6           = 54
	num7           = 55
	num8           = 56
	num9           = 57
	semicolon      = 59  /* ; */
	equal          = 61  /* = */
	a              = 65
	b              = 66
	c              = 67
	d              = 68
	e              = 69
	f              = 70
	g              = 71
	h              = 72
	i              = 73
	j              = 74
	k              = 75
	l              = 76
	m              = 77
	n              = 78
	o              = 79
	p              = 80
	q              = 81
	r              = 82
	s              = 83
	t              = 84
	u              = 85
	v              = 86
	w              = 87
	x              = 88
	y              = 89
	z              = 90
	leftBracket    = 91  /* [ */
	backslash      = 92  /* \ */
	rightBracket   = 93  /* ] */
	graveAccent    = 96  /* ` */
	world1         = 161 /* non-US #1 */
	world2         = 162 /* non-US #2 */
	escape         = 256
	enter          = 257
	tab            = 258
	backspace      = 259
	insert         = 260
	delete         = 261
	right          = 262
	left           = 263
	down           = 264
	up             = 265
	pageUp         = 266
	pageDown       = 267
	home           = 268
	end            = 269
	capsLock       = 280
	scrollLock     = 281
	numLock        = 282
	printScreen    = 283
	pause          = 284
	fn0            = 289
	fn1            = 290
	fn2            = 291
	fn3            = 292
	fn4            = 293
	fn5            = 294
	fn6            = 295
	fn7            = 296
	fn8            = 297
	fn9            = 298
	fn10           = 299
	fn11           = 300
	fn12           = 301
	fn13           = 302
	fn14           = 303
	fn15           = 304
	fn16           = 305
	fn17           = 306
	fn18           = 307
	fn19           = 308
	fn20           = 309
	fn21           = 310
	fn22           = 311
	fn23           = 312
	fn24           = 313
	fn25           = 314
	kp0            = 320
	kp1            = 321
	kp2            = 322
	kp3            = 323
	kp4            = 324
	kp5            = 325
	kp6            = 326
	kp7            = 327
	kp8            = 328
	kp9            = 329
	kpDecimal      = 330
	kpDivide       = 331
	kpMultiply     = 332
	kpSubtract     = 333
	kpAdd          = 334
	kpEnter        = 335
	kpEqual        = 336
	leftShift      = 340
	leftControl    = 341
	leftAlt        = 342
	leftSuper      = 343
	rightShift     = 344
	rightControl   = 345
	rightAlt       = 346
	rightSuper     = 347
	menu           = 348
}

Gamepad button number

type GamepadButton* = enum {
	a
	b
	x
	y
	lt
	rt
	lb
	rb
	select
	start
	up
	down
	left
	right
	lstick
	rstick
	_count
}

Gamepad stick number

type GamepadStick* = enum {
	left
	right
}

fn getMousePos

fn getMousePos*(): th::Vf2 {

Returns the position of mouse cursor in relation to the screen.

fn getGlobalMousePos

fn getGlobalMousePos*(): th::Vf2 {

Returns the position of mouse cursor in relation to cam.

fn isPressed

fn isPressed*(code: Key): bool {

Returns true if key is pressed. Either use codes defined in the file above, or pass lower case char/number.

fn isPressedc

fn isPressedc*(code: char): bool {

Like isPressed, but you can pass char as the code.

fn isJustPressed

fn isJustPressed*(code: Key): bool {

Returns, whether code was just pressed this loop.

fn isJustPressedc

fn isJustPressedc*(code: char): bool {

Like isJustPressed, but you can pass char as the code.

fn isPressedRepeat

fn isPressedRepeat*(code: Key): bool {

Returns, whether code was just pressed this loop, with key repeat.

fn isPressedRepeatc

fn isPressedRepeatc*(code: char): bool {

Like isPressedRepeat, but you can pass char as the code.

fn isJustReleased

fn isJustReleased*(code: Key): bool {

Returns true if a key was just released.

fn isJustReleasedc

fn isJustReleasedc*(code: char): bool {

Like isJustReleased, but you can pass char as the code.

fn clear

fn clear*(code: Key) {

Clears both the pressed and justPressed state of a code.

fn clearc

fn clearc*(code: char) {

Like clear, but you can pass char as the code.

fn getStr

fn getStr*(): str {

Returns a string entered by the user in the last cycle.

fn getMouseDelta

fn getMouseDelta*(): th::Vf2 {

Returns the difference between mouse positions in the last cycle. Will work even if window.freezeCursor is enabled.

fn getMouseScroll

fn getMouseScroll*(): th::Vf2 {

Returns the scroll wheel value

fn gamepads

fn gamepads*(): []Gamepad {

Returns a list of gamepads that are currently connected.

fn gamepad

fn gamepad*(): Gamepad {

Returns the connected gamepad.

fn isPressed

fn (g: ^Gamepad) isPressed*(button: GamepadButton): bool {

Returns true if the gamepad button is pressed.

fn isJustPressed

fn (g: ^Gamepad) isJustPressed*(button: GamepadButton): bool {

Returns true if the gamepad button was just pressed.

fn isJustReleased

fn (g: ^Gamepad) isJustReleased*(button: GamepadButton): bool {

Returns true if the gamepad button was just released.

fn pressure

fn (g: ^Gamepad) pressure*(button: GamepadButton): th::fu {

Returns the pressure of the gamepad button in the range [0, 1].

fn stick

fn (g: ^Gamepad) stick*(stick: GamepadStick): th::Vf2 {

Returns the movement of the gamepad stick in the range [-1, 1] for each axis.

fn rumble

fn (g: ^Gamepad) rumble*(left, right: th::fu) {

Rumbles/vibrates the gamepad.