Class | Rubygame::EventTriggers::KeyPressTrigger |
In: |
lib/rubygame/event_triggers.rb
lib/rubygame/event_triggers.rb |
Parent: | Object |
KeyPressTrigger is an event trigger which fires when a key on the keyboard is pressed down (i.e. KeyPressed). See also KeyReleaseTrigger.
This trigger can be configured to fire for any key, or a specific key. It can also fire depending on which modifier keys are held (ctrl, shift, alt, etc.).
NOTE: This trigger only works with the new-style KeyPressed event class, not with the older KeyDownEvent. See EventQueue#enable_new_style_events
Initialize a new instance of KeyPressTrigger with the given key and modifier keys.
key: | the key symbol to detect, or :any (default) to detect any key. (Symbol, optional) |
mods: | an Array of one or more modifier key symbols, or :none to detect key
presses with exactly no modifiers, or :any (default) to detect any key
modifiers.
Valid modifiers are:
:alt, :ctrl, :shift, and :meta will match either the left version or right version (e.g. :left_alt or :right_alt). |
Example:
# Matches any key press, regardless of the key or modifiers. KeyPressTrigger.new # Matches the 'A' key with any (or no) modifiers. KeyPressTrigger.new( :a ) # Matches the 'A' with both Ctrl and Shift modifiers. KeyPressTrigger.new( :a, [:ctrl, :shift] ) # Matches the 'A' with both Left Ctrl and Left Shift modifiers. KeyPressTrigger.new( :a, [:left_ctrl, :left_shift] )
Initialize a new instance of KeyPressTrigger with the given key and modifier keys.
key: | the key symbol to detect, or :any (default) to detect any key. (Symbol, optional) |
mods: | an Array of one or more modifier key symbols, or :none to detect key
presses with exactly no modifiers, or :any (default) to detect any key
modifiers.
Valid modifiers are:
:alt, :ctrl, :shift, and :meta will match either the left version or right version (e.g. :left_alt or :right_alt). |
Example:
# Matches any key press, regardless of the key or modifiers. KeyPressTrigger.new # Matches the 'A' key with any (or no) modifiers. KeyPressTrigger.new( :a ) # Matches the 'A' with both Ctrl and Shift modifiers. KeyPressTrigger.new( :a, [:ctrl, :shift] ) # Matches the 'A' with both Left Ctrl and Left Shift modifiers. KeyPressTrigger.new( :a, [:left_ctrl, :left_shift] )
Returns true if the event is a KeyPressed event and the event‘s key and mods BOTH match the trigger‘s expectations.
Key matches if either of these is true:
Modifiers matches if any of these is true:
Returns true if the event is a KeyPressed event and the event‘s key and mods BOTH match the trigger‘s expectations.
Key matches if either of these is true:
Modifiers matches if any of these is true: