Sha256: 403c9ffd2cfef80e15a5110b54b196ca7ee4476569ae05b5feded3038e6aa148

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# mac-event-monitor

A Library to Monitor User Interactions

## Installation

    $ gem install mac-event-monitor

## Usage

    require 'mac-event-monitor'
    
    monitor = Mac::EventMonitor::Monitor.new

### Monitor Mouse Event

    monitor.add_listener(:mouse_down) do |event|
      puts [event.location.x, event.location.y].join(',')
    end
    monitor.run

### Monitor Keyboard Event

You need to enable "Access to assistive devices" in the Universal Access preference pane to monitor keyboard event.

    monitor.add_listener(:key_down) do |event|
      p event.keycode
      p event.shift_key?
    end
    monitor.run

### Record/Play Events

```
ruby recorder.rb | ruby player.rb
```

recorder.rb

```ruby
require 'mac-event-monitor'
require 'json'

e = Mac::EventMonitor::Monitor.new
events = []
e.add_listener {|e|
  events << e
}
e.run(3)

puts events.to_json
```

player.rb

```ruby
require 'mac-event-monitor'
require 'mac-robot'
require 'json'

events = JSON.parse(ARGF.read)
robot = Mac::Robot.new

return if events.size == 0

events.each_with_index do |event, index|
  case event.type
  when :mouse_move
    robot.mouse_move(event.location.x, event.location.y)
  end

  if n = events[index + 1]
    sleep n.time - event.time
  end
end
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mac-event-monitor-0.2.1 README.md