Sha256: c799bc22be4e8a0a44dab3631f1f76134d0ddc3f5e9062e6163e07b3b2e54877

Contents?: true

Size: 1.15 KB

Versions: 76

Compression:

Stored size: 1.15 KB

Contents

module SwtKeyHelper
  def keypress(key)
    if key =~ /^Cmd/
      mod_key = 4194304
      char = key.downcase[-1]
      keycode = key.downcase[-1]
    elsif key =~ /^Ctrl/
      mod_key = 262144
      keycode = key.downcase[-1]
      char = key.downcase[-1] - "A".downcase[-1] + 1
    else
      raise "unknown mod key"
    end
    post(Swt::SWT::KeyDown, 0, mod_key, 0)
    post(Swt::SWT::KeyDown, char, keycode, mod_key)
    post(Swt::SWT::KeyUp, char, keycode, mod_key)
    post(Swt::SWT::KeyUp, 0, mod_key, mod_key)
  end
  
  def post(type, char, keycode, state_mask)
    p [:post, type, char, keycode, state_mask]
    event = Swt::Widgets::Event.new
    event.type = type
    event.character = char
    event.keyCode = keycode
    event.stateMask = state_mask
    Redcar::ApplicationSWT.display.post(event)
  end
end

World(SwtKeyHelper)

When /^I press m"([^\"]*)" l"([^\"]*)" w"([^\"]*)"$/ do |key_mac, key_linux, key_windows|
  case Redcar.platform
  when :osx
    key = key_mac
  when :linux
    key = key_linux
  when :windows
    key = key_windows
  end
puts "pressing #{key}"
  keypress(key)
  while Redcar::ApplicationSWT.display.read_and_dispatch
    
  end
end

Version data entries

76 entries across 76 versions & 2 rubygems

Version Path
redcar-0.13 plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.13.5dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.13.4dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.13.3dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.13.2dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.13.1dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-0.12.1 plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.13.0dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-0.12 plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.27dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.26dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.25dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.24dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.23dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.22dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.21dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.20dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.19dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.18dev plugins/edit_view/features/step_definitions/key_steps.rb
redcar-dev-0.12.17dev plugins/edit_view/features/step_definitions/key_steps.rb