mac-event-monitor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ module Mac
2
+ module EventMonitor
3
+ class MouseEvent < Event
4
+ attr_reader :location, :button
5
+
6
+ def initialize(type, location_as_str, button)
7
+ super(type)
8
+
9
+ @location = parse_location(location_as_str)
10
+ @button = button
11
+ end
12
+
13
+ private
14
+
15
+ def parse_location(location_as_str)
16
+ Struct.new(:x, :y).new(*location_as_str.scan(/[\d\.]+/).map {|v| v.to_f })
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ module Mac
2
+ module EventMonitor
3
+ class Event
4
+ attr_reader :type
5
+
6
+ class << self
7
+ def create_from_description(description)
8
+ _, *atts_as_string = description.split(/\s+/)
9
+
10
+ attrs = atts_as_string.inject({}) do |result, attr_as_string|
11
+ name, value = attr_as_string.scan(/^([^=]+)=(.+)$/)[0]
12
+ result[name.to_sym] = value
13
+ result
14
+ end
15
+
16
+ case attrs[:type]
17
+ when 'LMouseUp'
18
+ MouseEvent.new(:mouse_up, attrs[:loc], :left)
19
+ when 'RMouseUp'
20
+ MouseEvent.new(:mouse_up, attrs[:loc], :right)
21
+ when 'OMouseUp'
22
+ MouseEvent.new(:mouse_up, attrs[:loc], :other)
23
+ when 'LMouseDown'
24
+ MouseEvent.new(:mouse_down, attrs[:loc], :left)
25
+ when 'RMouseDown'
26
+ MouseEvent.new(:mouse_down, attrs[:loc], :right)
27
+ when 'OMouseDown'
28
+ MouseEvent.new(:mouse_down, attrs[:loc], :other)
29
+ when 'MouseMoved'
30
+ MouseEvent.new(:mouse_move, attrs[:loc], nil)
31
+ when 'LMouseDragged'
32
+ MouseEvent.new(:mouse_drag, attrs[:loc], :left)
33
+ when 'RMouseDragged'
34
+ MouseEvent.new(:mouse_drag, attrs[:loc], :right)
35
+ when 'OMouseDragged'
36
+ MouseEvent.new(:mouse_drag, attrs[:loc], :other)
37
+ end
38
+ end
39
+ end
40
+
41
+ def initialize(type)
42
+ @type = type
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ module Mac
2
+ module EventMonitor
3
+ class Monitor
4
+ def initialize
5
+ @listeners = {}
6
+ end
7
+
8
+ def add_listener(type, &block)
9
+ @listeners[type] ||= []
10
+ @listeners[type] << block
11
+ end
12
+
13
+ def run
14
+ run_forever
15
+ end
16
+
17
+ def receive_event(str)
18
+ event = Event.create_from_description(str)
19
+
20
+ (@listeners[event.type] || []).each do |block|
21
+ block.call(event)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Mac
2
+ module EventMonitor
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'mac-event-monitor/version'
2
+
3
+ module Mac
4
+ module EventMonitor
5
+ end
6
+ end
7
+
8
+ require 'event_monitor'
9
+ require 'mac-event-monitor/monitor.rb'
10
+ require 'mac-event-monitor/event.rb'
11
+ require 'mac-event-monitor/event/mouse_event.rb'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/mac-event-monitor/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["youpy"]
6
+ gem.email = ["youpy@buycheapviagraonlinenow.com"]
7
+ gem.description = %q{A Library to Monitor User Interaction}
8
+ gem.summary = %q{A Library to Monitor User Interaction}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "mac-event-monitor"
15
+ gem.extensions = ["ext/event_monitor/extconf.rb"]
16
+ gem.require_paths = ["lib"]
17
+ gem.version = Mac::EventMonitor::VERSION
18
+
19
+ gem.add_development_dependency('rspec', ['~> 2.8.0'])
20
+ gem.add_development_dependency('mac-robot')
21
+ gem.add_development_dependency('eventmachine')
22
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ include Mac::EventMonitor
4
+
5
+ describe Event do
6
+ it 'should create event from description' do
7
+ event = Event.create_from_description('NSEvent: type=LMouseDown loc=(618,524) time=1136789.4 flags=0x100 win=0x0 winNum=17310 ctxt=0x0 evNum=14883 click=1 buttonNumber=0 pressure=1')
8
+
9
+ event.should be_an_instance_of(MouseEvent)
10
+ event.type.should equal(:mouse_down)
11
+ event.button.should equal(:left)
12
+ event.location.x.should be_an_instance_of(Float)
13
+ event.location.y.should be_an_instance_of(Float)
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ include Mac::EventMonitor
4
+
5
+ describe Monitor do
6
+ subject do
7
+ Monitor.new
8
+ end
9
+
10
+ it 'should monitor mouse down events' do
11
+ pending 'how to test?'
12
+
13
+ monitor = subject
14
+ result = false
15
+
16
+ monitor.add_listener(:mouse_down) do |event|
17
+ result = true
18
+ end
19
+
20
+ result.should_not be_true
21
+
22
+ monitor.run
23
+
24
+ result.should be_true
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'eventmachine'
5
+ require 'mac-robot'
6
+ require 'mac-event-monitor'
7
+
8
+ # This file was generated by the `rspec --init` command. Conventionally, all
9
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
10
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
11
+ # loaded once.
12
+ #
13
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
14
+ RSpec.configure do |config|
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.run_all_when_everything_filtered = true
17
+ config.filter_run :focus
18
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mac-event-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - youpy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70120877918140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70120877918140
25
+ - !ruby/object:Gem::Dependency
26
+ name: mac-robot
27
+ requirement: &70120877917700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70120877917700
36
+ - !ruby/object:Gem::Dependency
37
+ name: eventmachine
38
+ requirement: &70120877917240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70120877917240
47
+ description: A Library to Monitor User Interaction
48
+ email:
49
+ - youpy@buycheapviagraonlinenow.com
50
+ executables: []
51
+ extensions:
52
+ - ext/event_monitor/extconf.rb
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - ext/event_monitor/event_monitor.h
62
+ - ext/event_monitor/event_monitor.m
63
+ - ext/event_monitor/extconf.rb
64
+ - ext/lib/mkmf.rb
65
+ - lib/mac-event-monitor.rb
66
+ - lib/mac-event-monitor/event.rb
67
+ - lib/mac-event-monitor/event/mouse_event.rb
68
+ - lib/mac-event-monitor/monitor.rb
69
+ - lib/mac-event-monitor/version.rb
70
+ - mac-event-monitor.gemspec
71
+ - spec/mac-event-monitor/event_spec.rb
72
+ - spec/mac-event-monitor/monitor_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: ''
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -873940957044106889
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -873940957044106889
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.10
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: A Library to Monitor User Interaction
104
+ test_files:
105
+ - spec/mac-event-monitor/event_spec.rb
106
+ - spec/mac-event-monitor/monitor_spec.rb
107
+ - spec/spec_helper.rb