mac-robot 0.3.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +55 -8
- data/README.rdoc +4 -0
- data/VERSION +1 -1
- data/ext/event_dispatcher/event_dispatcher.m +4 -0
- data/ext/event_dispatcher/extconf.rb +2 -1
- data/ext/util/extconf.rb +2 -1
- data/ext/util/util.m +16 -0
- data/lib/mac-robot.rb +24 -2
- data/mac-robot.gemspec +0 -0
- data/spec/mac-robot_spec.rb +22 -1
- metadata +48 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9855222330a767946be0b647797086cda4513eee3813e87d5aa6b0a7ed246b1b
|
4
|
+
data.tar.gz: 549a65285d0ef8f09c8f1a07054973f7bc317a9f039b0957ebe4fe7a79b27ea7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 499ef63790c67f397444e6cb88f4a7d533d0313cd94be3d4f95e1b9c54a5ff68e01ad701340f82a483ca4683dcb4874e26f3fcd6ae50cb4dedb173cdb8e1a68c
|
7
|
+
data.tar.gz: b21908c6e3069ea74d7d32e7ad61d7f475144d046c077b2de18c82b85373ae24ba2bbcad1e039c7ba9c9dfcb389d639404e39907ada83efb05e85143a0e01fd0
|
data/Gemfile
CHANGED
@@ -6,7 +6,9 @@ source "http://rubygems.org"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
+
gem "rake", "< 11.0"
|
10
|
+
gem "json", "~> 2.5.1"
|
9
11
|
gem "rspec", "~> 2.8.0"
|
10
12
|
gem "bundler"
|
11
|
-
gem "jeweler", "~>
|
13
|
+
gem "jeweler", "~> 2.3.9"
|
12
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,57 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.4.0)
|
5
|
+
builder (3.2.4)
|
6
|
+
descendants_tracker (0.0.4)
|
7
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
4
8
|
diff-lcs (1.1.3)
|
5
|
-
|
6
|
-
|
7
|
-
|
9
|
+
faraday (0.9.2)
|
10
|
+
multipart-post (>= 1.2, < 3)
|
11
|
+
git (1.8.1)
|
12
|
+
rchardet (~> 1.8)
|
13
|
+
github_api (0.16.0)
|
14
|
+
addressable (~> 2.4.0)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
16
|
+
faraday (~> 0.8, < 0.10)
|
17
|
+
hashie (>= 3.4)
|
18
|
+
mime-types (>= 1.16, < 3.0)
|
19
|
+
oauth2 (~> 1.0)
|
20
|
+
hashie (4.1.0)
|
21
|
+
highline (2.0.3)
|
22
|
+
jeweler (2.3.9)
|
23
|
+
builder
|
24
|
+
bundler
|
8
25
|
git (>= 1.2.5)
|
26
|
+
github_api (~> 0.16.0)
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (>= 1.5.10)
|
29
|
+
psych
|
9
30
|
rake
|
10
31
|
rdoc
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
32
|
+
semver2
|
33
|
+
json (2.5.1)
|
34
|
+
jwt (2.2.2)
|
35
|
+
mime-types (2.99.3)
|
36
|
+
mini_portile2 (2.5.0)
|
37
|
+
multi_json (1.15.0)
|
38
|
+
multi_xml (0.6.0)
|
39
|
+
multipart-post (2.1.1)
|
40
|
+
nokogiri (1.11.3)
|
41
|
+
mini_portile2 (~> 2.5.0)
|
42
|
+
racc (~> 1.4)
|
43
|
+
oauth2 (1.4.7)
|
44
|
+
faraday (>= 0.8, < 2.0)
|
45
|
+
jwt (>= 1.0, < 3.0)
|
46
|
+
multi_json (~> 1.3)
|
47
|
+
multi_xml (~> 0.5)
|
48
|
+
rack (>= 1.2, < 3)
|
49
|
+
psych (3.3.1)
|
50
|
+
racc (1.5.2)
|
51
|
+
rack (2.2.3)
|
52
|
+
rake (10.5.0)
|
53
|
+
rchardet (1.8.0)
|
54
|
+
rdoc (6.3.0)
|
15
55
|
rspec (2.8.0)
|
16
56
|
rspec-core (~> 2.8.0)
|
17
57
|
rspec-expectations (~> 2.8.0)
|
@@ -20,11 +60,18 @@ GEM
|
|
20
60
|
rspec-expectations (2.8.0)
|
21
61
|
diff-lcs (~> 1.1.2)
|
22
62
|
rspec-mocks (2.8.0)
|
63
|
+
semver2 (3.4.2)
|
64
|
+
thread_safe (0.3.6)
|
23
65
|
|
24
66
|
PLATFORMS
|
25
67
|
ruby
|
26
68
|
|
27
69
|
DEPENDENCIES
|
28
70
|
bundler
|
29
|
-
jeweler (~>
|
71
|
+
jeweler (~> 2.3.9)
|
72
|
+
json (~> 2.5.1)
|
73
|
+
rake (< 11.0)
|
30
74
|
rspec (~> 2.8.0)
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.1.4
|
data/README.rdoc
CHANGED
@@ -12,7 +12,11 @@ A Library to Automate User Interactions
|
|
12
12
|
|
13
13
|
robot.mouse_press
|
14
14
|
robot.mouse_move(250, 250)
|
15
|
+
robot.mouse_drag(100, 200)
|
15
16
|
robot.mouse_release
|
17
|
+
|
18
|
+
robot.mouse_current_location # => 100, 200
|
19
|
+
|
16
20
|
robot.scroll_wheel(:x => 10, :y => -20, :z => 5)
|
17
21
|
|
18
22
|
=== Automate keyboard
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.2
|
@@ -16,6 +16,8 @@ VALUE createInstance() {
|
|
16
16
|
return Data_Wrap_Struct(rb_cEventDispatcher, 0, cEventDispatcher_free, obj);
|
17
17
|
}
|
18
18
|
|
19
|
+
// https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/doc/uid/TP40003550-CH3g-C016985
|
20
|
+
// XXX: support right button and center button
|
19
21
|
CGEventType getEventTypeFromValue(VALUE value)
|
20
22
|
{
|
21
23
|
const char *typeStr;
|
@@ -29,6 +31,8 @@ CGEventType getEventTypeFromValue(VALUE value)
|
|
29
31
|
type = kCGEventLeftMouseUp;
|
30
32
|
} else if(strcmp(typeStr, "mouse_move") == 0) {
|
31
33
|
type = kCGEventMouseMoved;
|
34
|
+
} else if(strcmp(typeStr, "mouse_drag") == 0) {
|
35
|
+
type = kCGEventLeftMouseDragged;
|
32
36
|
} else {
|
33
37
|
type = kCGEventNull;
|
34
38
|
}
|
@@ -6,6 +6,7 @@ require "mkmf"
|
|
6
6
|
|
7
7
|
# Name your extension
|
8
8
|
extension_name = 'event_dispatcher'
|
9
|
+
header_name = extension_name + '.h'
|
9
10
|
|
10
11
|
# Set your target name
|
11
12
|
dir_config(extension_name)
|
@@ -18,7 +19,7 @@ begin
|
|
18
19
|
rescue
|
19
20
|
end
|
20
21
|
|
21
|
-
have_header(
|
22
|
+
have_header(header_name)
|
22
23
|
|
23
24
|
# Do the work
|
24
25
|
create_makefile(extension_name)
|
data/ext/util/extconf.rb
CHANGED
@@ -6,6 +6,7 @@ require "mkmf"
|
|
6
6
|
|
7
7
|
# Name your extension
|
8
8
|
extension_name = 'util'
|
9
|
+
header_name = extension_name + '.h'
|
9
10
|
|
10
11
|
# Set your target name
|
11
12
|
dir_config(extension_name)
|
@@ -18,7 +19,7 @@ begin
|
|
18
19
|
rescue
|
19
20
|
end
|
20
21
|
|
21
|
-
have_header(
|
22
|
+
have_header(header_name)
|
22
23
|
|
23
24
|
# Do the work
|
24
25
|
create_makefile(extension_name)
|
data/ext/util/util.m
CHANGED
@@ -47,6 +47,21 @@ static VALUE mUtil_get_display_pixel_size(int argc, VALUE *argv, VALUE self)
|
|
47
47
|
return result;
|
48
48
|
}
|
49
49
|
|
50
|
+
static VALUE mUtil_get_mouse_current_location(int argc, VALUE *argv, VALUE self)
|
51
|
+
{
|
52
|
+
VALUE result;
|
53
|
+
CGEventRef event;
|
54
|
+
|
55
|
+
event = CGEventCreate(NULL);
|
56
|
+
CGPoint loc = CGEventGetLocation(event);
|
57
|
+
|
58
|
+
result = rb_ary_new();
|
59
|
+
rb_ary_push(result, INT2NUM(loc.x));
|
60
|
+
rb_ary_push(result, INT2NUM(loc.y));
|
61
|
+
|
62
|
+
return result;
|
63
|
+
}
|
64
|
+
|
50
65
|
void Init_util(void){
|
51
66
|
VALUE rb_mMac, rb_cRobot, rb_mUtil;
|
52
67
|
|
@@ -55,4 +70,5 @@ void Init_util(void){
|
|
55
70
|
rb_mUtil = rb_define_module_under(rb_cRobot, "Util");
|
56
71
|
rb_define_singleton_method(rb_mUtil, "get_pixel_color", mUtil_get_pixel_color, -1);
|
57
72
|
rb_define_singleton_method(rb_mUtil, "get_display_pixel_size", mUtil_get_display_pixel_size, -1);
|
73
|
+
rb_define_singleton_method(rb_mUtil, "get_mouse_current_location", mUtil_get_mouse_current_location, -1);
|
58
74
|
}
|
data/lib/mac-robot.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'event_dispatcher'
|
2
|
-
require 'util'
|
1
|
+
require 'event_dispatcher.h'
|
2
|
+
require 'util.h'
|
3
3
|
|
4
4
|
module Mac
|
5
5
|
class Robot
|
@@ -17,6 +17,7 @@ module Mac
|
|
17
17
|
def initialize
|
18
18
|
@x = 0
|
19
19
|
@y = 0
|
20
|
+
|
20
21
|
@state = :mouse_up
|
21
22
|
@dispatcher = EventDispatcher.new
|
22
23
|
end
|
@@ -38,6 +39,18 @@ module Mac
|
|
38
39
|
mouse_event(:left, :mouse_move)
|
39
40
|
end
|
40
41
|
|
42
|
+
def mouse_drag(x, y)
|
43
|
+
@x = x
|
44
|
+
@y = y
|
45
|
+
|
46
|
+
mouse_event(:left, :mouse_drag)
|
47
|
+
end
|
48
|
+
|
49
|
+
def mouse_current_location
|
50
|
+
loc = Util.get_mouse_current_location
|
51
|
+
Struct.new(:x, :y).new(*loc)
|
52
|
+
end
|
53
|
+
|
41
54
|
def key_press(keycode)
|
42
55
|
keyboard_event(keycode, 1)
|
43
56
|
end
|
@@ -59,6 +72,15 @@ module Mac
|
|
59
72
|
raise OutOfResolution if x < 0 || y < 0
|
60
73
|
raise OutOfResolution if display_pixel_size.width < x || display_pixel_size.height < y
|
61
74
|
|
75
|
+
# workarownd for exeption occurs when x == display_pixel_size.width
|
76
|
+
#
|
77
|
+
# *** Assertion failure in -[NSBitmapImageRep initWithCGImage:], /SourceCache/AppKit/AppKit-1265/AppKit.subproj/NSBitmapImageRep.m:1286
|
78
|
+
# An uncaught exception was raised
|
79
|
+
# Invalid parameter not satisfying: cgImage != NULL
|
80
|
+
if display_pixel_size.width == x
|
81
|
+
x = x - 0.1
|
82
|
+
end
|
83
|
+
|
62
84
|
color = Util.get_pixel_color(x, y)
|
63
85
|
Struct.new(:red, :green, :blue, :alpha).new(*color)
|
64
86
|
end
|
data/mac-robot.gemspec
CHANGED
Binary file
|
data/spec/mac-robot_spec.rb
CHANGED
@@ -9,8 +9,11 @@ describe Mac::Robot do
|
|
9
9
|
describe 'mouse event' do
|
10
10
|
it 'should simulate mouse event' do
|
11
11
|
subject.mouse_move(20, 0)
|
12
|
+
sleep 0.2
|
12
13
|
subject.mouse_press(:left)
|
13
|
-
|
14
|
+
sleep 0.2
|
15
|
+
subject.mouse_move(20, 200)
|
16
|
+
sleep 0.2
|
14
17
|
subject.mouse_release(:left)
|
15
18
|
end
|
16
19
|
end
|
@@ -53,5 +56,23 @@ describe Mac::Robot do
|
|
53
56
|
}.should raise_error(Mac::Robot::OutOfResolution)
|
54
57
|
end
|
55
58
|
end
|
59
|
+
|
60
|
+
it 'should get color from rightmost pixel' do
|
61
|
+
display_pixel_size = subject.display_pixel_size
|
62
|
+
|
63
|
+
color = subject.get_pixel_color(display_pixel_size.width, 0)
|
64
|
+
color.red.should be_a_kind_of(Float)
|
65
|
+
color.green.should be_a_kind_of(Float)
|
66
|
+
color.blue.should be_a_kind_of(Float)
|
67
|
+
color.alpha.should be_a_kind_of(Float)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'current mouse location' do
|
72
|
+
it 'should have current mouse location' do
|
73
|
+
subject.mouse_move(20, 0)
|
74
|
+
subject.mouse_current_location.x.should eql(20)
|
75
|
+
subject.mouse_current_location.y.should eql(0)
|
76
|
+
end
|
56
77
|
end
|
57
78
|
end
|
metadata
CHANGED
@@ -1,64 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mac-robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- youpy
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-04-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "<"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.5.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.5.1
|
14
41
|
- !ruby/object:Gem::Dependency
|
15
42
|
name: rspec
|
16
43
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
44
|
requirements:
|
19
|
-
- - ~>
|
45
|
+
- - "~>"
|
20
46
|
- !ruby/object:Gem::Version
|
21
47
|
version: 2.8.0
|
22
48
|
type: :development
|
23
49
|
prerelease: false
|
24
50
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
51
|
requirements:
|
27
|
-
- - ~>
|
52
|
+
- - "~>"
|
28
53
|
- !ruby/object:Gem::Version
|
29
54
|
version: 2.8.0
|
30
55
|
- !ruby/object:Gem::Dependency
|
31
56
|
name: bundler
|
32
57
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
58
|
requirements:
|
35
|
-
- -
|
59
|
+
- - ">="
|
36
60
|
- !ruby/object:Gem::Version
|
37
61
|
version: '0'
|
38
62
|
type: :development
|
39
63
|
prerelease: false
|
40
64
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
65
|
requirements:
|
43
|
-
- -
|
66
|
+
- - ">="
|
44
67
|
- !ruby/object:Gem::Version
|
45
68
|
version: '0'
|
46
69
|
- !ruby/object:Gem::Dependency
|
47
70
|
name: jeweler
|
48
71
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
72
|
requirements:
|
51
|
-
- - ~>
|
73
|
+
- - "~>"
|
52
74
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
75
|
+
version: 2.3.9
|
54
76
|
type: :development
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
79
|
requirements:
|
59
|
-
- - ~>
|
80
|
+
- - "~>"
|
60
81
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
82
|
+
version: 2.3.9
|
62
83
|
description: A Library to Automate User Interactions
|
63
84
|
email: youpy@buycheapviagraonlinenow.com
|
64
85
|
executables: []
|
@@ -69,8 +90,8 @@ extra_rdoc_files:
|
|
69
90
|
- LICENSE.txt
|
70
91
|
- README.rdoc
|
71
92
|
files:
|
72
|
-
- .document
|
73
|
-
- .rspec
|
93
|
+
- ".document"
|
94
|
+
- ".rspec"
|
74
95
|
- Gemfile
|
75
96
|
- Gemfile.lock
|
76
97
|
- LICENSE.txt
|
@@ -91,29 +112,24 @@ files:
|
|
91
112
|
homepage: http://github.com/youpy/mac-robot
|
92
113
|
licenses:
|
93
114
|
- MIT
|
94
|
-
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
95
117
|
rdoc_options: []
|
96
118
|
require_paths:
|
97
119
|
- lib
|
98
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
-
none: false
|
100
121
|
requirements:
|
101
|
-
- -
|
122
|
+
- - ">="
|
102
123
|
- !ruby/object:Gem::Version
|
103
124
|
version: '0'
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
hash: 625334772670347707
|
107
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
126
|
requirements:
|
110
|
-
- -
|
127
|
+
- - ">="
|
111
128
|
- !ruby/object:Gem::Version
|
112
129
|
version: '0'
|
113
130
|
requirements: []
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
specification_version: 3
|
131
|
+
rubygems_version: 3.1.6
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
118
134
|
summary: A Library to Automate User Interactions
|
119
135
|
test_files: []
|