Sha256: 9ebb0362b8b01a746a85e2956452031e10e40093e5c70c08bc23ffd0f671669a

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module RAutomation
  module Adapter
    module Win32
      class Mouse
        def initialize(window)
          @window = window
        end

        def move(coords={})
          @last_position = coords = (@last_position || position).merge(coords)

          until position[:x] == coords[:x] && position[:y] == coords[:y]
            @window.activate
            Functions.set_cursor_pos coords[:x], coords[:y]
          end
        end

        def position
          Functions.get_cursor_pos
        end

        def click
          send_input down_event, up_event
        end

        def press
          send_input down_event, down_event
        end

        def release
          send_input up_event, up_event
        end

        private

        def send_input *inputs
          @window.activate
          Functions.send_input inputs.size, inputs.join, inputs[0].size
        end

        def down_event
          input Constants::MOUSEEVENTF_LEFTDOWN
        end

        def up_event
          input Constants::MOUSEEVENTF_LEFTUP
        end

        def input flag
          mouse_input = Array.new(7, 0)
          mouse_input[0] = Constants::INPUT_MOUSE
          mouse_input[4] = flag
          Platform.is_x86? ? mouse_input.pack('L*') : mouse_input.pack('QLLLLQQ')
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rautomation-2.0.1-x86-mingw32 lib/rautomation/adapter/win_32/mouse.rb
rautomation-2.0.1-x64-mingw32 lib/rautomation/adapter/win_32/mouse.rb