mac-event-monitor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.log
20
+ *.o
21
+ Makefile
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mac-event-monitor.gemspec
4
+ gemspec
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,11 @@
1
+ #include <ruby.h>
2
+ #import <AppKit/AppKit.h>
3
+
4
+ @interface EventMonitorAppDelegate : NSObject <NSApplicationDelegate> {
5
+ id eventMonitor;
6
+ }
7
+
8
+ @property (assign) VALUE rb_monitor;
9
+
10
+ @end
11
+
@@ -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)