mac-robot 0.0.2 → 0.1.0
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/Rakefile +5 -0
- data/VERSION +1 -1
- data/ext/event_dispatcher/event_dispatcher.m +20 -0
- data/lib/mac-robot.rb +14 -2
- data/spec/mac-robot_spec.rb +12 -2
- metadata +8 -8
data/Rakefile
CHANGED
@@ -30,6 +30,11 @@ Jeweler::RubygemsDotOrgTasks.new
|
|
30
30
|
# after any change to the files in ext
|
31
31
|
ext_names = %w/event_dispatcher/
|
32
32
|
ext_names.each do |ext_name|
|
33
|
+
CLEAN.include Dir.glob("ext/#{ext_name}/*{.o,.log}")
|
34
|
+
CLEAN.include "ext/#{ext_name}/Makefile"
|
35
|
+
CLOBBER.include "ext/#{ext_name}/#{ext_name}.bundle"
|
36
|
+
CLOBBER.include "lib/#{ext_name}.bundle"
|
37
|
+
|
33
38
|
file "lib/#{ext_name}.bundle" =>
|
34
39
|
Dir.glob("ext/#{ext_name}/*{.rb,.m}") do
|
35
40
|
Dir.chdir("ext/#{ext_name}") do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -78,6 +78,25 @@ static VALUE cEventDispatcher_dispatchMouseEvent(int argc, VALUE *argv, VALUE se
|
|
78
78
|
return Qnil;
|
79
79
|
}
|
80
80
|
|
81
|
+
// http://forums.macrumors.com/showthread.php?t=780577
|
82
|
+
static VALUE cEventDispatcher_dispatchKeyboardEvent(int argc, VALUE *argv, VALUE self)
|
83
|
+
{
|
84
|
+
VALUE keycode, keydown;
|
85
|
+
CGEventRef event;
|
86
|
+
|
87
|
+
rb_scan_args(argc, argv, "2", &keycode, &keydown);
|
88
|
+
|
89
|
+
event = CGEventCreateKeyboardEvent(
|
90
|
+
NULL,
|
91
|
+
(CGKeyCode)NUM2INT(keycode),
|
92
|
+
(bool)NUM2INT(keydown));
|
93
|
+
|
94
|
+
CGEventPost(kCGHIDEventTap, event);
|
95
|
+
CFRelease(event);
|
96
|
+
|
97
|
+
return Qnil;
|
98
|
+
}
|
99
|
+
|
81
100
|
void Init_event_dispatcher(void){
|
82
101
|
VALUE rb_mMac, rb_cRobot;
|
83
102
|
|
@@ -86,4 +105,5 @@ void Init_event_dispatcher(void){
|
|
86
105
|
rb_cEventDispatcher = rb_define_class_under(rb_cRobot, "EventDispatcher", rb_cObject);
|
87
106
|
rb_define_singleton_method(rb_cEventDispatcher, "new", cEventDispatcher_new, -1);
|
88
107
|
rb_define_method(rb_cEventDispatcher, "dispatchMouseEvent", cEventDispatcher_dispatchMouseEvent, -1);
|
108
|
+
rb_define_method(rb_cEventDispatcher, "dispatchKeyboardEvent", cEventDispatcher_dispatchKeyboardEvent, -1);
|
89
109
|
}
|
data/lib/mac-robot.rb
CHANGED
@@ -14,6 +14,7 @@ module Mac
|
|
14
14
|
@x = 0
|
15
15
|
@y = 0
|
16
16
|
@state = :mouse_up
|
17
|
+
@dispatcher = EventDispatcher.new
|
17
18
|
end
|
18
19
|
|
19
20
|
def mouse_press(button = :left)
|
@@ -33,11 +34,22 @@ module Mac
|
|
33
34
|
mouse_event(:left, :mouse_move)
|
34
35
|
end
|
35
36
|
|
37
|
+
def key_press(keycode)
|
38
|
+
keyboard_event(keycode, 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
def key_release(keycode)
|
42
|
+
keyboard_event(keycode, 0)
|
43
|
+
end
|
44
|
+
|
36
45
|
private
|
37
46
|
|
38
47
|
def mouse_event(button, type)
|
39
|
-
dispatcher
|
40
|
-
|
48
|
+
@dispatcher.dispatchMouseEvent(@x, @y, BUTTONS[button], type)
|
49
|
+
end
|
50
|
+
|
51
|
+
def keyboard_event(keycode, keydown)
|
52
|
+
@dispatcher.dispatchKeyboardEvent(keycode, keydown)
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
data/spec/mac-robot_spec.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
+
# how to test???
|
3
4
|
describe Mac::Robot do
|
4
5
|
subject do
|
5
6
|
Mac::Robot.new
|
6
7
|
end
|
7
8
|
|
8
9
|
describe 'mouse event' do
|
9
|
-
# how to test???
|
10
10
|
it 'should simulate mouse event' do
|
11
|
+
subject.mouse_move(20, 0)
|
11
12
|
subject.mouse_press(:left)
|
12
|
-
subject.mouse_move(
|
13
|
+
subject.mouse_move(20, 250)
|
13
14
|
subject.mouse_release(:left)
|
14
15
|
end
|
15
16
|
end
|
17
|
+
|
18
|
+
describe 'keyboard event' do
|
19
|
+
it 'should simulate keyboard event' do
|
20
|
+
[0x04, 0x0e, 0x25, 0x25, 0x1f].each do |keycode|
|
21
|
+
subject.key_press(keycode)
|
22
|
+
subject.key_release(keycode)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
16
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mac-robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-29 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70197386120920 !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: *70197386120920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70197386119180 !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: *70197386119180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70197386117420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 1.8.3
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70197386117420
|
47
47
|
description: A Library to Automate User Interactions
|
48
48
|
email: youpy@buycheapviagraonlinenow.com
|
49
49
|
executables: []
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash:
|
86
|
+
hash: 3428969405361014881
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|