mac-event-monitor 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mac-event-monitor
2
2
 
3
- A Library to Monitor User Interaction
3
+ A Library to Monitor User Interactions
4
4
 
5
5
  ## Installation
6
6
 
@@ -5,6 +5,8 @@
5
5
  id eventMonitor;
6
6
  }
7
7
 
8
+ -(void)onTimeout:(NSTimer *) timer;
9
+
8
10
  @property (assign) VALUE rb_monitor;
9
11
 
10
12
  @end
@@ -33,28 +33,51 @@
33
33
  }];
34
34
  }
35
35
 
36
+ - (void)onTimeout:(NSTimer *)timer {
37
+ NSEvent *event;
38
+
39
+ [[NSApplication sharedApplication] stop:nil];
40
+ //[NSEvent removeMonitor:eventMonitor];
41
+
42
+ // http://www.cocoabuilder.com/archive/cocoa/219842-nsapp-stop.html
43
+ event = [NSEvent otherEventWithType: NSApplicationDefined
44
+ location: NSMakePoint(0,0)
45
+ modifierFlags: 0
46
+ timestamp: 0.0
47
+ windowNumber: 0
48
+ context: nil
49
+ subtype: 0
50
+ data1: 0
51
+ data2: 0];
52
+ [NSApp postEvent: event atStart: true];
53
+ }
54
+
36
55
  @end
37
56
 
38
57
  static VALUE rb_cMonitor;
39
58
 
40
- static VALUE cMonitor_run_forever(int argc, VALUE *argv, VALUE self)
59
+ static VALUE cMonitor_run_app(int argc, VALUE *argv, VALUE self)
41
60
  {
42
61
  EventMonitorAppDelegate *delegate;
62
+ VALUE stopAfter;
63
+
64
+ rb_scan_args(argc, argv, "1", &stopAfter);
43
65
 
44
66
  delegate = [EventMonitorAppDelegate new];
45
67
  delegate.rb_monitor = self;
46
68
 
47
69
  [NSApplication sharedApplication];
48
70
  [NSApp setDelegate: delegate];
49
- [NSApp run];
50
71
 
51
- return Qnil;
52
- }
72
+ if(stopAfter) {
73
+ [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)NUM2INT(stopAfter)
74
+ target:delegate
75
+ selector:@selector(onTimeout:)
76
+ userInfo:nil
77
+ repeats:NO];
78
+ }
53
79
 
54
- static VALUE cMonitor_stop(int argc, VALUE *argv, VALUE self)
55
- {
56
- [NSApplication sharedApplication];
57
- [NSApp stop:nil];
80
+ [NSApp run];
58
81
 
59
82
  return Qnil;
60
83
  }
@@ -65,6 +88,5 @@ void Init_event_monitor(void){
65
88
  rb_mMac = rb_define_module("Mac");
66
89
  rb_mEventMonitor = rb_define_module_under(rb_mMac, "EventMonitor");
67
90
  rb_cMonitor = rb_define_class_under(rb_mEventMonitor, "Monitor", rb_cObject);
68
- rb_define_method(rb_cMonitor, "stop", cMonitor_stop, -1);
69
- rb_define_method(rb_cMonitor, "run_forever", cMonitor_run_forever, -1);
91
+ rb_define_method(rb_cMonitor, "run_app", cMonitor_run_app, -1);
70
92
  }
@@ -10,8 +10,8 @@ module Mac
10
10
  @listeners[type] << block
11
11
  end
12
12
 
13
- def run
14
- run_forever
13
+ def run(stop_after = nil)
14
+ run_app(stop_after)
15
15
  end
16
16
 
17
17
  def receive_event(str)
@@ -1,5 +1,5 @@
1
1
  module Mac
2
2
  module EventMonitor
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -4,8 +4,8 @@ require File.expand_path('../lib/mac-event-monitor/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["youpy"]
6
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}
7
+ gem.description = %q{A Library to Monitor User Interactions}
8
+ gem.summary = %q{A Library to Monitor User Interactions}
9
9
  gem.homepage = ""
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -8,19 +8,32 @@ describe Monitor do
8
8
  end
9
9
 
10
10
  it 'should monitor mouse down events' do
11
- pending 'how to test?'
11
+ result = 0
12
+ robot = Mac::Robot.new
12
13
 
13
14
  monitor = subject
14
- result = false
15
-
16
15
  monitor.add_listener(:mouse_down) do |event|
17
- result = true
16
+ result += 1
18
17
  end
19
18
 
20
- result.should_not be_true
19
+ result.should be_zero
20
+
21
+ EM.run do
22
+ [1, 1.5].each do |t|
23
+ EM.add_timer(t) do
24
+ robot.mouse_press
25
+ end
26
+ end
21
27
 
22
- monitor.run
28
+ EM.add_timer(2) do
29
+ EM.stop
30
+ end
31
+
32
+ EM.add_periodic_timer(0.1) do
33
+ monitor.run(0.1)
34
+ end
35
+ end
23
36
 
24
- result.should be_true
37
+ result.should be >= 2
25
38
  end
26
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mac-event-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70120877918140 !ruby/object:Gem::Requirement
16
+ requirement: &70149660258920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70120877918140
24
+ version_requirements: *70149660258920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mac-robot
27
- requirement: &70120877917700 !ruby/object:Gem::Requirement
27
+ requirement: &70149660258500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70120877917700
35
+ version_requirements: *70149660258500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: eventmachine
38
- requirement: &70120877917240 !ruby/object:Gem::Requirement
38
+ requirement: &70149660258040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,8 +43,8 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70120877917240
47
- description: A Library to Monitor User Interaction
46
+ version_requirements: *70149660258040
47
+ description: A Library to Monitor User Interactions
48
48
  email:
49
49
  - youpy@buycheapviagraonlinenow.com
50
50
  executables: []
@@ -85,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: -873940957044106889
88
+ hash: -357376635066606538
89
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
@@ -94,13 +94,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  segments:
96
96
  - 0
97
- hash: -873940957044106889
97
+ hash: -357376635066606538
98
98
  requirements: []
99
99
  rubyforge_project:
100
100
  rubygems_version: 1.8.10
101
101
  signing_key:
102
102
  specification_version: 3
103
- summary: A Library to Monitor User Interaction
103
+ summary: A Library to Monitor User Interactions
104
104
  test_files:
105
105
  - spec/mac-event-monitor/event_spec.rb
106
106
  - spec/mac-event-monitor/monitor_spec.rb