Module: Castanaut::Plugin::Keystack
- Defined in:
- lib/plugins/keystack.rb
Overview
keystack castanaut plugin by trevor wennblom <[email protected]> 2009-04-23
used in gnu screen demo
http://ninecoldwinters.com/ferro/gnuscreenscreencast
castanaut can be found here: gadgets.inventivelabs.com.au/castanaut
support multiple modifier keys to achieve the likes of Command-Tab
modifiers allowed are :control, :command, :option, and :shift these can be passed as an array
this does not account for input customization, so if you use dvorak your results will be interesting.
license compatible with castanaut released under the terms of the WTFPL sam.zoy.org/wtfpl
Instance Method Summary collapse
-
#keycode(k) ⇒ Object
keycode press keycode is a number mapped to a specific key on your keyboard, ‘0’ and greater.
-
#keycode_using(k, *modifiers) ⇒ Object
keycode press with one or more modifier keys keycode is a number mapped to a specific key on your keyboard, ‘0’ and greater.
-
#keystroke(k) ⇒ Object
keystroke such as ‘a’ or ‘my sentence’.
-
#keystroke_literal(k, *modifiers) ⇒ Object
keystroke literal such as ‘return’ or ‘tab’ example keystroke_literal(‘tab’).
-
#keystroke_literal_using(k, *modifiers) ⇒ Object
keystroke literal such as ‘return’ or ‘tab’ with one or more modifier keys example keystroke_literal_using(‘tab’, :command) # Command-Tab switch windows.
-
#keystroke_using(k, *modifiers) ⇒ Object
keystroke with one or more modifier keys example keystroke(‘z’, :command) keystroke(‘z’, :command, :shift) keystroke(‘z’, [:command, :shift]).
Instance Method Details
#keycode(k) ⇒ Object
keycode press keycode is a number mapped to a specific key on your keyboard, ‘0’ and greater
29 30 31 32 33 |
# File 'lib/plugins/keystack.rb', line 29 def keycode(k) k = k.to_i # if a number as type String was passed ascript = %Q`tell application "System Events" to key code #{k}` execute_applescript(ascript) end |
#keycode_using(k, *modifiers) ⇒ Object
keycode press with one or more modifier keys keycode is a number mapped to a specific key on your keyboard, ‘0’ and greater
51 52 53 54 55 56 |
# File 'lib/plugins/keystack.rb', line 51 def keycode_using(k, *modifiers) k = k.to_i # if a number as type String was passed m = modifiers_to_array(modifiers) ascript = %Q`tell application "System Events" to key code #{k} using #{m}` execute_applescript(ascript) end |
#keystroke(k) ⇒ Object
keystroke such as ‘a’ or ‘my sentence’
36 37 38 39 |
# File 'lib/plugins/keystack.rb', line 36 def keystroke(k) ascript = %Q`tell application "System Events" to keystroke "#{k}"` execute_applescript(ascript) end |
#keystroke_literal(k, *modifiers) ⇒ Object
keystroke literal such as ‘return’ or ‘tab’ example
keystroke_literal('tab')
44 45 46 47 |
# File 'lib/plugins/keystack.rb', line 44 def keystroke_literal(k, *modifiers) ascript = %Q`tell application "System Events" to keystroke #{k}` execute_applescript(ascript) end |
#keystroke_literal_using(k, *modifiers) ⇒ Object
keystroke literal such as ‘return’ or ‘tab’ with one or more modifier keys example
keystroke_literal_using('tab', :command) # Command-Tab switch windows
72 73 74 75 76 |
# File 'lib/plugins/keystack.rb', line 72 def keystroke_literal_using(k, *modifiers) m = modifiers_to_array(modifiers) ascript = %Q`tell application "System Events" to keystroke #{k} using #{m}` execute_applescript(ascript) end |
#keystroke_using(k, *modifiers) ⇒ Object
keystroke with one or more modifier keys example
keystroke('z', :command)
keystroke('z', :command, :shift)
keystroke('z', [:command, :shift])
63 64 65 66 67 |
# File 'lib/plugins/keystack.rb', line 63 def keystroke_using(k, *modifiers) m = modifiers_to_array(modifiers) ascript = %Q`tell application "System Events" to keystroke "#{k}" using #{m}` execute_applescript(ascript) end |