Class: Rubygame::Events::KeyPressed
- Inherits:
-
Object
- Object
- Rubygame::Events::KeyPressed
- Includes:
- KeyboardEvent
- Defined in:
- lib/rubygame/events/keyboard_events.rb
Overview
KeyPressed is an event class which occurs when a key on the keyboard is pressed down.
This class gains #key and #modifiers readers from the KeyboardEvent mixin module.
It also has #string, which is a UTF8 string containing the text character that was generated by the keystroke; if nothing was generated, #string will be the empty string, “”.
The #string attribute is useful for for taking text input (e.g. in a GUI). It supports UTF8 Unicode characters, and works correctly on many different types of keyboards.
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Attributes included from KeyboardEvent
Instance Method Summary collapse
-
#initialize(key, modifiers = [], string = "") ⇒ KeyPressed
constructor
Create a new KeyPressed instance.
Constructor Details
#initialize(key, modifiers = [], string = "") ⇒ KeyPressed
Create a new KeyPressed instance.
- key
-
a key symbol for the key that was pressed or released. (Symbol, required)
- modifiers
-
an Array of key symbols for the modifier keys that were active when the event occured. (Array, optional)
- string
-
a String containing the text character that was generated by the keystroke, or “” if nothing was generated. (String, optional)
95 96 97 98 99 100 101 |
# File 'lib/rubygame/events/keyboard_events.rb', line 95 def initialize( key, modifiers=[], string="" ) super( key, modifiers ) @string = string.to_str.dup @string.freeze end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
79 80 81 |
# File 'lib/rubygame/events/keyboard_events.rb', line 79 def string @string end |