Class: Hokusai::Automation::DriverCommands::TriggerKeyboard
- Defined in:
- ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Attributes inherited from Base
#last_parent, #request_id, #state, #status
Instance Method Summary collapse
- #execute(blocks, canvas, input) ⇒ Object
-
#initialize(state) ⇒ TriggerKeyboard
constructor
A new instance of TriggerKeyboard.
- #keys ⇒ Object
- #location ⇒ Object
- #on_complete ⇒ Object
-
#to_hml_keygroup(decode_key) ⇒ Object
Transforms a DecodedKey to an array of ‘LibHokusai::HmlInputKey`.
- #to_hml_keys ⇒ Object
Methods inherited from Base
#matches_block, #matches_blocks, #mouse_center, #mouse_move
Constructor Details
#initialize(state) ⇒ TriggerKeyboard
Returns a new instance of TriggerKeyboard.
6 7 8 9 10 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 6 def initialize(state) @exception = nil super end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
4 5 6 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 4 def exception @exception end |
Instance Method Details
#execute(blocks, canvas, input) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 28 def execute(blocks, canvas, input) return unless matches_block(blocks[0]) Log.info { "Trigger keypress on #{blocks[0].class}".colorize(:cyan) } decode_key = keys.shift mouse_center(canvas, input) state = LibHokusai::HmlInputMouseButton.create(clicked: true) LibHokusai.(input, state, 0) begin key_results = to_hml_keygroup(decode_key) LibHokusai.hoku_input_keyboard_start(input) key_results.each do |key| Log.info { "populating #{key}"} LibHokusai.hoku_input_keyboard_set_key(input, key, true) end LibHokusai.hoku_input_keyboard_stop(input) rescue Automation::Error => ex keys.clear self.exeception = ex done! end end |
#keys ⇒ Object
16 17 18 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 16 def keys @keys ||= KeysTranscoder.decode(state[:keys]) end |
#location ⇒ Object
12 13 14 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 12 def location state[:uuid] end |
#on_complete ⇒ Object
20 21 22 23 24 25 26 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 20 def on_complete if keys.empty? done! end return exception || true end |
#to_hml_keygroup(decode_key) ⇒ Object
Transforms a DecodedKey to an array of ‘LibHokusai::HmlInputKey`
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 60 def to_hml_keygroup(decode_key) key_group = [] case decode_key when Array decode_key.each do |key| if hml_key = CODE_TO_HML_KEY[key] key_group << hml_key else raise Automation::Exception.new("Error translating key to HmlInput: #{key} not found") end end else if hml_key CODE_TO_HML_KEY[decode_key] key_group << hml_key else raise Automation::Exception.new("Error translating key to HmlInput: #{key} not found") end end key_group end |
#to_hml_keys ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'ui/src/hokusai/automation/driver_commands/trigger_keyboard.rb', line 83 def to_hml_keys hml_keys = [] keys.each do |decode_key| hml_keys << to_hml_keygroup(decode_key) end hml_keys end |