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.
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +31 -0
- data/ext/event_monitor/event_monitor.h +11 -0
- data/ext/event_monitor/event_monitor.m +70 -0
- data/ext/event_monitor/extconf.rb +18 -0
- data/ext/lib/mkmf.rb +1837 -0
- data/lib/mac-event-monitor/event/mouse_event.rb +20 -0
- data/lib/mac-event-monitor/event.rb +46 -0
- data/lib/mac-event-monitor/monitor.rb +26 -0
- data/lib/mac-event-monitor/version.rb +5 -0
- data/lib/mac-event-monitor.rb +11 -0
- data/mac-event-monitor.gemspec +22 -0
- data/spec/mac-event-monitor/event_spec.rb +15 -0
- data/spec/mac-event-monitor/monitor_spec.rb +26 -0
- data/spec/spec_helper.rb +18 -0
- metadata +107 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 youpy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# mac-event-monitor
|
2
|
+
|
3
|
+
A Library to Monitor User Interaction
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install mac-event-monitor
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
require 'mac-event-monitor'
|
12
|
+
|
13
|
+
monitor = Mac::EventMonitor::Monitor.new
|
14
|
+
monitor.add_listener(:mouse_down) do |event|
|
15
|
+
puts [event.location.x, event.location.y].join(',')
|
16
|
+
end
|
17
|
+
monitor.run
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
|
6
|
+
ext_names = %w/event_monitor/
|
7
|
+
ext_names.each do |ext_name|
|
8
|
+
CLEAN.include Dir.glob("ext/#{ext_name}/*{.o,.log}")
|
9
|
+
CLEAN.include "ext/#{ext_name}/Makefile"
|
10
|
+
CLOBBER.include "ext/#{ext_name}/#{ext_name}.bundle"
|
11
|
+
CLOBBER.include "lib/#{ext_name}.bundle"
|
12
|
+
|
13
|
+
file "lib/#{ext_name}.bundle" =>
|
14
|
+
Dir.glob("ext/#{ext_name}/*{.rb,.m}") do
|
15
|
+
Dir.chdir("ext/#{ext_name}") do
|
16
|
+
ruby "extconf.rb"
|
17
|
+
sh "make"
|
18
|
+
end
|
19
|
+
cp "ext/#{ext_name}/#{ext_name}.bundle", "lib/"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :spec => "lib/#{ext_name}.bundle"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rspec/core'
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
28
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => :spec
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#import "event_monitor.h"
|
2
|
+
|
3
|
+
@implementation EventMonitorAppDelegate
|
4
|
+
|
5
|
+
@synthesize rb_monitor;
|
6
|
+
|
7
|
+
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
8
|
+
NSEventMask mask;
|
9
|
+
|
10
|
+
mask =
|
11
|
+
NSLeftMouseUpMask
|
12
|
+
| NSRightMouseUpMask
|
13
|
+
| NSOtherMouseUpMask
|
14
|
+
| NSLeftMouseDownMask
|
15
|
+
| NSRightMouseDownMask
|
16
|
+
| NSOtherMouseDownMask
|
17
|
+
| NSLeftMouseDraggedMask
|
18
|
+
| NSRightMouseDraggedMask
|
19
|
+
| NSOtherMouseDraggedMask
|
20
|
+
| NSMouseMovedMask
|
21
|
+
// | NSScrollWheelMask
|
22
|
+
// | NSTabletPointMask
|
23
|
+
// | NSTabletProximityMask
|
24
|
+
// | NSKeyDownMask
|
25
|
+
;
|
26
|
+
|
27
|
+
eventMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:mask
|
28
|
+
handler:^(NSEvent *incomingEvent) {
|
29
|
+
VALUE event;
|
30
|
+
|
31
|
+
event = rb_str_new2([[incomingEvent description] UTF8String]);
|
32
|
+
rb_funcall(rb_monitor, rb_intern("receive_event"), 1, event);
|
33
|
+
}];
|
34
|
+
}
|
35
|
+
|
36
|
+
@end
|
37
|
+
|
38
|
+
static VALUE rb_cMonitor;
|
39
|
+
|
40
|
+
static VALUE cMonitor_run_forever(int argc, VALUE *argv, VALUE self)
|
41
|
+
{
|
42
|
+
EventMonitorAppDelegate *delegate;
|
43
|
+
|
44
|
+
delegate = [EventMonitorAppDelegate new];
|
45
|
+
delegate.rb_monitor = self;
|
46
|
+
|
47
|
+
[NSApplication sharedApplication];
|
48
|
+
[NSApp setDelegate: delegate];
|
49
|
+
[NSApp run];
|
50
|
+
|
51
|
+
return Qnil;
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE cMonitor_stop(int argc, VALUE *argv, VALUE self)
|
55
|
+
{
|
56
|
+
[NSApplication sharedApplication];
|
57
|
+
[NSApp stop:nil];
|
58
|
+
|
59
|
+
return Qnil;
|
60
|
+
}
|
61
|
+
|
62
|
+
void Init_event_monitor(void){
|
63
|
+
VALUE rb_mMac, rb_mEventMonitor;
|
64
|
+
|
65
|
+
rb_mMac = rb_define_module("Mac");
|
66
|
+
rb_mEventMonitor = rb_define_module_under(rb_mMac, "EventMonitor");
|
67
|
+
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);
|
70
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
if RUBY_VERSION < '1.9.0'
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
3
|
+
end
|
4
|
+
|
5
|
+
require "mkmf"
|
6
|
+
|
7
|
+
# Name your extension
|
8
|
+
extension_name = 'event_monitor'
|
9
|
+
|
10
|
+
# Set your target name
|
11
|
+
dir_config(extension_name)
|
12
|
+
|
13
|
+
$LDFLAGS += ' -framework ApplicationServices -framework AppKit'
|
14
|
+
|
15
|
+
have_header(extension_name)
|
16
|
+
|
17
|
+
# Do the work
|
18
|
+
create_makefile(extension_name)
|