Module: Briar::UIAKeyboard::Language
- Defined in:
- lib/briar/keyboard/uia_keyboard_language.rb
Constant Summary collapse
- BRIAR_LANGUAGE_KEYS =
use the apple localization codes
{ :en => 'space', :de => 'Leerzeichen', :da => 'mellemrum', :th => 'วรรค', # could not decide what the language code should be (alt was ja-JP) :ja => '空白' }
Instance Method Summary collapse
- #english_keyboard?(opts = {}) ⇒ Boolean
- #german_keyboard?(opts = {}) ⇒ Boolean
-
#keyboard_has_international?(opts = {}) ⇒ Boolean
work in progress the number of buttons on the keyboard will be 3 <== there is no international button 4 <== there is an international button.
- #romaji_keyboard?(opts = {}) ⇒ Boolean
- #spacebar_has_label?(label, opts = {}) ⇒ Boolean
-
#spacebar_label(opts = {}) ⇒ Object
work in progress when looking at elements() the space bar will be at the penultimate index when looking at keys() the space bar index seems to float around.
- #touch_international_key(opts = {}) ⇒ Object
- #touch_international_until_language(language_key, opts = {}) ⇒ Object
Instance Method Details
#english_keyboard?(opts = {}) ⇒ Boolean
74 75 76 77 78 79 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 74 def english_keyboard? (opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] BRIAR_LANGUAGE_KEYS[:en] end |
#german_keyboard?(opts = {}) ⇒ Boolean
81 82 83 84 85 86 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 81 def german_keyboard? (opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] BRIAR_LANGUAGE_KEYS[:de] end |
#keyboard_has_international?(opts = {}) ⇒ Boolean
work in progress the number of buttons on the keyboard will be 3 <== there is no international button 4 <== there is an international button
22 23 24 25 26 27 28 29 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 22 def keyboard_has_international? (opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] res = uia('UIATarget.localTarget().frontMostApp().keyboard().buttons().length') = res['value'] == 4 end |
#romaji_keyboard?(opts = {}) ⇒ Boolean
88 89 90 91 92 93 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 88 def romaji_keyboard? (opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] BRIAR_LANGUAGE_KEYS[:ja] end |
#spacebar_has_label?(label, opts = {}) ⇒ Boolean
67 68 69 70 71 72 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 67 def (label, opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] .eql?(label) end |
#spacebar_label(opts = {}) ⇒ Object
work in progress when looking at elements() the space bar will be at the penultimate index when looking at keys() the space bar index seems to float around
57 58 59 60 61 62 63 64 65 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 57 def (opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] elm_count = uia('UIATarget.localTarget().frontMostApp().keyboard().elements().length')['value'] = elm_count - 2 res = uia("UIATarget.localTarget().frontMostApp().keyboard().elements()[#{}].label()") res['value'] end |
#touch_international_key(opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 31 def touch_international_key(opts={}) default_opts = {:wait_for_keyboard => false, :step_pause => 0.4} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] unless keyboard_has_international? screenshot_and_raise 'could not find an international key on the keyboard' end # the international button will be at index 1 # 3 <== return key # 2 <== Dictation key # 1 <== International key # 0 <== shift key res = uia('UIATarget.localTarget().frontMostApp().keyboard().buttons()[1].tap()') # sleep for a moment and let the keyboard settle into the new language sleep(opts[:step_pause]) res end |
#touch_international_until_language(language_key, opts = {}) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/briar/keyboard/uia_keyboard_language.rb', line 95 def touch_international_until_language(language_key, opts={}) default_opts = {:wait_for_keyboard => false} opts = default_opts.merge(opts) wait_for_keyboard if opts[:wait_for_keyboard] unless keyboard_has_international? screenshot_and_raise 'keyboard does not have an international key' end target = BRIAR_LANGUAGE_KEYS[language_key] if target.nil? screenshot_and_raise "unknown language key '#{language_key}'" end stop_at = return if target.eql?(stop_at) touch_international_key current = loop do break if current.eql?(target) touch_international_key current = if current.eql?(stop_at) screenshot_and_raise "could not find keyboard using key '#{language_key}' and space bar label '#{target}'" end end end |