mac-event-monitor 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/ext/event_monitor/event_monitor.h +2 -0
- data/ext/event_monitor/event_monitor.m +32 -10
- data/lib/mac-event-monitor/monitor.rb +2 -2
- data/lib/mac-event-monitor/version.rb +1 -1
- data/mac-event-monitor.gemspec +2 -2
- data/spec/mac-event-monitor/monitor_spec.rb +20 -7
- metadata +11 -11
data/README.md
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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, "
|
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
|
}
|
data/mac-event-monitor.gemspec
CHANGED
@@ -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
|
8
|
-
gem.summary = %q{A Library to Monitor User
|
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
|
-
|
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
|
16
|
+
result += 1
|
18
17
|
end
|
19
18
|
|
20
|
-
result.
|
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
|
-
|
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
|
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.
|
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: &
|
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: *
|
24
|
+
version_requirements: *70149660258920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mac-robot
|
27
|
-
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: *
|
35
|
+
version_requirements: *70149660258500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: eventmachine
|
38
|
-
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: *
|
47
|
-
description: A Library to Monitor User
|
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: -
|
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: -
|
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
|
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
|