mac-robot 0.5.4 → 0.5.5
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +22 -17
- data/Rakefile +1 -3
- data/VERSION +1 -1
- data/ext/util/util.m +5 -3
- data/lib/mac-robot.rb +17 -13
- data/mac-robot.gemspec +0 -0
- data/spec/mac-robot_spec.rb +21 -23
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60baeb22867d9f1b436e4ab27cf588224f168aa1fa26db06bc1b8750b92d784c
|
4
|
+
data.tar.gz: 0c86df74a65049916202344feeeaa727fafdd6c6442f118cc538c950a64e0471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92bddcbf3718d54c33785ac0b5cf95d92b276d0cd2e49eb5b6e479bca4e5f5425695a8d1f4fb6f2c5cb67921614fcd3e68bd39608a963a01e661b448626de6d7
|
7
|
+
data.tar.gz: cfb2d6448dfac40197d8117176b9c0880817f76ba85614d80afc21b8459ea891e79e052ca28c9c3f5d9c03963bd162b66af2e8e84ebbdf50058dbd386b518cb3
|
data/Gemfile
CHANGED
@@ -6,9 +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", "
|
9
|
+
gem "rake", ">= 12.3.3"
|
10
10
|
gem "json", "~> 2.5.1"
|
11
|
-
gem "rspec", "~>
|
11
|
+
gem "rspec", "~> 3.10.0"
|
12
12
|
gem "bundler"
|
13
13
|
gem "juwelier", "~> 2.4.9"
|
14
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -6,7 +6,7 @@ GEM
|
|
6
6
|
builder (3.2.4)
|
7
7
|
descendants_tracker (0.0.4)
|
8
8
|
thread_safe (~> 0.3, >= 0.3.1)
|
9
|
-
diff-lcs (1.
|
9
|
+
diff-lcs (1.4.4)
|
10
10
|
faraday (1.8.0)
|
11
11
|
faraday-em_http (~> 1.0)
|
12
12
|
faraday-em_synchrony (~> 1.0)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
faraday-net_http_persistent (1.2.0)
|
27
27
|
faraday-patron (1.0.0)
|
28
28
|
faraday-rack (1.0.0)
|
29
|
-
git (1.
|
29
|
+
git (1.11.0)
|
30
30
|
rchardet (~> 1.8)
|
31
31
|
github_api (0.19.0)
|
32
32
|
addressable (~> 2.4)
|
@@ -52,12 +52,12 @@ GEM
|
|
52
52
|
jwt (2.3.0)
|
53
53
|
kamelcase (0.0.2)
|
54
54
|
semver2 (~> 3)
|
55
|
-
mini_portile2 (2.
|
55
|
+
mini_portile2 (2.8.0)
|
56
56
|
multi_json (1.15.0)
|
57
57
|
multi_xml (0.6.0)
|
58
58
|
multipart-post (2.1.1)
|
59
|
-
nokogiri (1.
|
60
|
-
mini_portile2 (~> 2.
|
59
|
+
nokogiri (1.13.6)
|
60
|
+
mini_portile2 (~> 2.8.0)
|
61
61
|
racc (~> 1.4)
|
62
62
|
oauth2 (1.4.7)
|
63
63
|
faraday (>= 0.8, < 2.0)
|
@@ -68,18 +68,23 @@ GEM
|
|
68
68
|
psych (4.0.2)
|
69
69
|
public_suffix (4.0.6)
|
70
70
|
racc (1.6.0)
|
71
|
-
rack (2.2.3)
|
72
|
-
rake (
|
71
|
+
rack (2.2.3.1)
|
72
|
+
rake (13.0.6)
|
73
73
|
rchardet (1.8.0)
|
74
74
|
rdoc (6.3.3)
|
75
|
-
rspec (
|
76
|
-
rspec-core (~>
|
77
|
-
rspec-expectations (~>
|
78
|
-
rspec-mocks (~>
|
79
|
-
rspec-core (
|
80
|
-
|
81
|
-
|
82
|
-
|
75
|
+
rspec (3.10.0)
|
76
|
+
rspec-core (~> 3.10.0)
|
77
|
+
rspec-expectations (~> 3.10.0)
|
78
|
+
rspec-mocks (~> 3.10.0)
|
79
|
+
rspec-core (3.10.1)
|
80
|
+
rspec-support (~> 3.10.0)
|
81
|
+
rspec-expectations (3.10.1)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.10.0)
|
84
|
+
rspec-mocks (3.10.2)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.10.0)
|
87
|
+
rspec-support (3.10.3)
|
83
88
|
ruby2_keywords (0.0.5)
|
84
89
|
semver2 (3.4.2)
|
85
90
|
thread_safe (0.3.6)
|
@@ -91,8 +96,8 @@ DEPENDENCIES
|
|
91
96
|
bundler
|
92
97
|
json (~> 2.5.1)
|
93
98
|
juwelier (~> 2.4.9)
|
94
|
-
rake (
|
95
|
-
rspec (~>
|
99
|
+
rake (>= 12.3.3)
|
100
|
+
rspec (~> 3.10.0)
|
96
101
|
|
97
102
|
BUNDLED WITH
|
98
103
|
2.1.4
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.5
|
data/ext/util/util.m
CHANGED
@@ -15,7 +15,8 @@ static VALUE mUtil_get_pixel_color(int argc, VALUE *argv, VALUE self)
|
|
15
15
|
intX = NUM2INT(x);
|
16
16
|
intY = NUM2INT(y);
|
17
17
|
|
18
|
-
|
18
|
+
CGDirectDisplayID displayID = CGMainDisplayID();
|
19
|
+
image = CGDisplayCreateImageForRect(displayID, CGRectMake(intX, intY, 1, 1));
|
19
20
|
bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image];
|
20
21
|
CGImageRelease(image);
|
21
22
|
color = [bitmap colorAtX:0 y:0];
|
@@ -37,8 +38,9 @@ static VALUE mUtil_get_display_pixel_size(int argc, VALUE *argv, VALUE self)
|
|
37
38
|
int width, height;
|
38
39
|
VALUE result;
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
CGDirectDisplayID displayID = CGMainDisplayID();
|
42
|
+
width = (int)CGDisplayPixelsWide(displayID);
|
43
|
+
height = (int)CGDisplayPixelsHigh(displayID);
|
42
44
|
|
43
45
|
result = rb_ary_new();
|
44
46
|
rb_ary_push(result, INT2NUM(width));
|
data/lib/mac-robot.rb
CHANGED
@@ -3,16 +3,14 @@ require 'util'
|
|
3
3
|
|
4
4
|
module Mac
|
5
5
|
class Robot
|
6
|
-
class Error < StandardError
|
7
|
-
|
6
|
+
class Error < StandardError
|
7
|
+
end
|
8
|
+
class OutOfResolution < Error
|
9
|
+
end
|
8
10
|
|
9
11
|
attr_reader :x, :y
|
10
12
|
|
11
|
-
BUTTONS = {
|
12
|
-
:left => 0,
|
13
|
-
:right => 1,
|
14
|
-
:center => 2
|
15
|
-
}
|
13
|
+
BUTTONS = { left: 0, right: 1, center: 2 }
|
16
14
|
|
17
15
|
def initialize
|
18
16
|
@x = 0
|
@@ -70,16 +68,16 @@ module Mac
|
|
70
68
|
|
71
69
|
def get_pixel_color(x, y)
|
72
70
|
raise OutOfResolution if x < 0 || y < 0
|
73
|
-
|
71
|
+
if display_pixel_size.width < x || display_pixel_size.height < y
|
72
|
+
raise OutOfResolution
|
73
|
+
end
|
74
74
|
|
75
75
|
# workarownd for exeption occurs when x == display_pixel_size.width
|
76
76
|
#
|
77
77
|
# *** Assertion failure in -[NSBitmapImageRep initWithCGImage:], /SourceCache/AppKit/AppKit-1265/AppKit.subproj/NSBitmapImageRep.m:1286
|
78
78
|
# An uncaught exception was raised
|
79
79
|
# Invalid parameter not satisfying: cgImage != NULL
|
80
|
-
if display_pixel_size.width == x
|
81
|
-
x = x - 0.1
|
82
|
-
end
|
80
|
+
x = x - 0.1 if display_pixel_size.width == x
|
83
81
|
|
84
82
|
color = Util.get_pixel_color(x, y)
|
85
83
|
Struct.new(:red, :green, :blue, :alpha).new(*color)
|
@@ -97,7 +95,13 @@ module Mac
|
|
97
95
|
|
98
96
|
def scroll_wheel_event(unit, scroll_y, scroll_x = 0, scroll_z = 0)
|
99
97
|
wheel_count = 3
|
100
|
-
@dispatcher.dispatchScrollWheelEvent(
|
98
|
+
@dispatcher.dispatchScrollWheelEvent(
|
99
|
+
unit,
|
100
|
+
wheel_count,
|
101
|
+
scroll_y,
|
102
|
+
scroll_x,
|
103
|
+
scroll_z
|
104
|
+
)
|
101
105
|
end
|
102
106
|
|
103
107
|
def scroll_count_extract(args = {})
|
@@ -118,7 +122,7 @@ module Mac
|
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
121
|
-
return
|
125
|
+
return scroll_y, scroll_x, scroll_z
|
122
126
|
end
|
123
127
|
|
124
128
|
def keyboard_event(keycode, keydown)
|
data/mac-robot.gemspec
CHANGED
Binary file
|
data/spec/mac-robot_spec.rb
CHANGED
@@ -2,9 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
# how to test???
|
4
4
|
describe Mac::Robot do
|
5
|
-
subject
|
6
|
-
Mac::Robot.new
|
7
|
-
end
|
5
|
+
subject { Mac::Robot.new }
|
8
6
|
|
9
7
|
describe 'mouse event' do
|
10
8
|
it 'should simulate mouse event' do
|
@@ -20,10 +18,10 @@ describe Mac::Robot do
|
|
20
18
|
|
21
19
|
describe 'scroll wheel event' do
|
22
20
|
it 'should simulate scroll wheel event' do
|
23
|
-
subject.scroll_wheel_line(:
|
24
|
-
subject.scroll_wheel(:
|
25
|
-
subject.scroll_wheel_pixel(:
|
26
|
-
subject.scroll_wheel_pixel(:
|
21
|
+
subject.scroll_wheel_line(y: 10) # down 10 lines
|
22
|
+
subject.scroll_wheel(y: -10) # up 10 lines
|
23
|
+
subject.scroll_wheel_pixel(x: 10, y: -20, z: 5)
|
24
|
+
subject.scroll_wheel_pixel(y: 20, x: -10, z: -5)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
@@ -39,21 +37,21 @@ describe Mac::Robot do
|
|
39
37
|
describe 'color' do
|
40
38
|
it 'should get color from given coordinate' do
|
41
39
|
color = subject.get_pixel_color(0, 0)
|
42
|
-
color.red.
|
43
|
-
color.green.
|
44
|
-
color.blue.
|
45
|
-
color.alpha.
|
40
|
+
expect(color.red).to be_a_kind_of(Float)
|
41
|
+
expect(color.green).to be_a_kind_of(Float)
|
42
|
+
expect(color.blue).to be_a_kind_of(Float)
|
43
|
+
expect(color.alpha).to be_a_kind_of(Float)
|
46
44
|
end
|
47
45
|
|
48
46
|
it 'should raise if given coordinate is out of resolution' do
|
49
47
|
[9999, -1].each do |p|
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
expect { subject.get_pixel_color(p, 0) }.to raise_error(
|
49
|
+
Mac::Robot::OutOfResolution
|
50
|
+
)
|
53
51
|
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
expect { subject.get_pixel_color(0, p) }.to raise_error(
|
53
|
+
Mac::Robot::OutOfResolution
|
54
|
+
)
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
@@ -61,18 +59,18 @@ describe Mac::Robot do
|
|
61
59
|
display_pixel_size = subject.display_pixel_size
|
62
60
|
|
63
61
|
color = subject.get_pixel_color(display_pixel_size.width, 0)
|
64
|
-
color.red.
|
65
|
-
color.green.
|
66
|
-
color.blue.
|
67
|
-
color.alpha.
|
62
|
+
expect(color.red).to be_a_kind_of(Float)
|
63
|
+
expect(color.green).to be_a_kind_of(Float)
|
64
|
+
expect(color.blue).to be_a_kind_of(Float)
|
65
|
+
expect(color.alpha).to be_a_kind_of(Float)
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
69
|
describe 'current mouse location' do
|
72
70
|
it 'should have current mouse location' do
|
73
71
|
subject.mouse_move(20, 0)
|
74
|
-
subject.mouse_current_location.x.
|
75
|
-
subject.mouse_current_location.y.
|
72
|
+
expect(subject.mouse_current_location.x).to eql(20)
|
73
|
+
expect(subject.mouse_current_location.y).to eql(0)
|
76
74
|
end
|
77
75
|
end
|
78
76
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mac-robot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youpy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 12.3.3
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 12.3.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.10.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.10.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|