Class: Rubygame::KeyDownEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/rubygame/event.rb

Overview

Indicates that a keyboard key was pressed.

This event has these attributes:

string

a human-readable string telling what key was pressed, or nil. See #key2str.

key

the integer keysym for the key. These can be compared with the K_* constants in the Rubygame module, e.g. Rubygame::K_A.

mods

an Array of zero or more keysyms indicating which modifier keys were being pressed when the key was pressed. You can compare with these constants in the Rubygame module:

K_RSHIFT

shift key (right side)

K_LSHIFT

shift key (left side)

K_RCTRL

ctrl key (right side)

K_LCTRL

ctrl key (left side)

K_RALT

alt key (right side)

K_LALT

alt key (left side)

K_RMETA

meta key (right side)

K_LMETA

meta key (left side)

K_RSUPER

super key, aka. Windows key (right side)

K_LSUPER

super key, aka. Windows key (left side)

K_RALT

alt key (right side)

K_NUMLOCK

num lock

K_CAPSLOCK

caps lock

K_MODE

mode key

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, mods) ⇒ KeyDownEvent

Create a new KeyDownEvent.

key

either an integer keysym (e.g. Rubygame::K_A) or string (e.g. “a”)

mods

array of modifier keysyms



206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/rubygame/event.rb', line 206

def initialize(key,mods)
	if key.kind_of? Integer
		@key = key
		@string = Rubygame.key2str(key, mods) #a string or nil
	elsif key.kind_of? String
		@key = Rubygame::Key::ASCII2KEY[key]
		if @key != nil
			@string = key
		else
			raise(ArgumentError,"First argument of KeyDownEvent.new() must be an Integer KeySym (like K_A) or a ASCII-like String (like \"a\" or \"A\"). Got %s (%s)"%[key,key.class])
		end
	end
	@mods = mods
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



200
201
202
# File 'lib/rubygame/event.rb', line 200

def key
  @key
end

#modsObject

Returns the value of attribute mods.



200
201
202
# File 'lib/rubygame/event.rb', line 200

def mods
  @mods
end

#stringObject

Returns the value of attribute string.



200
201
202
# File 'lib/rubygame/event.rb', line 200

def string
  @string
end