Star Ruby Ruby extension library for creating 2D games

StarRuby::Input

This module controls input device.

Enumeration of keys

In starruby, keys will be enumerated as below.

Keyboard

EnumerationCommon name
:a - :zAlphabet
:d0 - :d9Number
:f1 - :f15Function keys
:numpad0 - :numpad9Numpad keys
:add+ (Numpad)
:backBackSpace?
:capslockCaps Lock
:clearClear
:decimal. (Numpad)
:deleteDelete
:divide/ (Numpad)
:downDown Arrow
:helpHelp
:homeHome
:endEnd
:enterEnter / Return
:escapeEsc
:insertInsert
:lcontrolkeyLeft Ctrl
:leftLeft Arrow
:lmenuLeft Alt
:lshiftkeyLeft Shift
:multiply* (Numpad)
:numlockNumLock?
:pagedownPage Down
:pageupPage Up
:rcontrolkeyLeft Ctrl
:rightRight Arrow
:rmenuRight Alt
:rshiftkeyRight Shift
:scrollScroll Lock
:spaceSpace
:subtract- (Numpad)
:tabTab
:upUp Arrow

Gamepad

EnumerationCommon name
:downDown
:leftLeft
:rightRight
:upUp
(Integer)Buttons correspond to the integer value (start from 1)

Mouse

EnumerationCommon name
:leftLeft Button
:middleMiddle Button
:rightRight Button

Module Methods

Input.gamepad_count

Get number of gamepads connected.

Input.keys(device, options = {})

Returns array of pushed buttons.

Specify type of device by device Values below can be used.

EnumerationCommon name
:keyboardKeyboard
:gamepadGamepad
:mouseMouse

If no buttons are pushed, return empty array.

As options, you need to pass Hash. Keys and values below can be selected.

KeyValueDefault
:device_numberDevice number starts from 0. Only valid for gamepads.0
:durationDuration (unit is frames) of detecting key pushed. -1 means infinity.-1
:delaySet the delay (unit is frames) after the key is pushed. -1 means infinity (no consequent detection). Used for key-repeating.-1
:intervalInterval for detecting the key pushed. Used for key-repeating.0

(TODO: Insert graph)

Input.mouse_location

Get an array of mouse position ([(X-Coordinate), (Y-Coordinate)])

© Copyright 2010 Hajime Hoshi