mac-robot 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/ext/event_dispatcher/extconf.rb +1 -1
- data/ext/{event_dispatcher → lib}/mkmf.rb +0 -0
- data/ext/util/extconf.rb +18 -0
- data/ext/util/util.h +2 -0
- data/ext/util/util.m +42 -0
- data/lib/mac-robot.rb +6 -0
- data/spec/mac-robot_spec.rb +10 -0
- metadata +14 -10
data/README.rdoc
CHANGED
@@ -13,6 +13,13 @@ A Library to Automate User Interactions
|
|
13
13
|
robot.mouse_press
|
14
14
|
robot.mouse_move(250, 250)
|
15
15
|
robot.mouse_release
|
16
|
+
|
17
|
+
=== Automate Keyboard
|
18
|
+
|
19
|
+
[0x04, 0x0e, 0x25, 0x25, 0x1f].each do |keycode|
|
20
|
+
subject.key_press(keycode)
|
21
|
+
subject.key_release(keycode)
|
22
|
+
end
|
16
23
|
|
17
24
|
== Contributing to mac-robot
|
18
25
|
|
data/Rakefile
CHANGED
@@ -28,7 +28,7 @@ Jeweler::RubygemsDotOrgTasks.new
|
|
28
28
|
# rule to build the extension: this says
|
29
29
|
# that the extension should be rebuilt
|
30
30
|
# after any change to the files in ext
|
31
|
-
ext_names = %w/event_dispatcher/
|
31
|
+
ext_names = %w/event_dispatcher util/
|
32
32
|
ext_names.each do |ext_name|
|
33
33
|
CLEAN.include Dir.glob("ext/#{ext_name}/*{.o,.log}")
|
34
34
|
CLEAN.include "ext/#{ext_name}/Makefile"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
File without changes
|
data/ext/util/extconf.rb
ADDED
@@ -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 = 'util'
|
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)
|
data/ext/util/util.h
ADDED
data/ext/util/util.m
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#import "util.h"
|
2
|
+
|
3
|
+
static VALUE mUtil_get_pixel_color(int argc, VALUE *argv, VALUE self)
|
4
|
+
{
|
5
|
+
VALUE x, y;
|
6
|
+
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
7
|
+
int intX, intY;
|
8
|
+
VALUE result;
|
9
|
+
CGImageRef image;
|
10
|
+
NSBitmapImageRep *bitmap;
|
11
|
+
NSColor *color;
|
12
|
+
|
13
|
+
rb_scan_args(argc, argv, "2", &x, &y);
|
14
|
+
|
15
|
+
intX = NUM2INT(x);
|
16
|
+
intY = NUM2INT(y);
|
17
|
+
|
18
|
+
image = CGDisplayCreateImageForRect((CGDirectDisplayID)0, CGRectMake(intX, intY, 1, 1));
|
19
|
+
bitmap = [[NSBitmapImageRep alloc] initWithCGImage:image];
|
20
|
+
CGImageRelease(image);
|
21
|
+
color = [bitmap colorAtX:0 y:0];
|
22
|
+
|
23
|
+
result = rb_ary_new();
|
24
|
+
rb_ary_push(result, rb_float_new((float)[color redComponent]));
|
25
|
+
rb_ary_push(result, rb_float_new((float)[color greenComponent]));
|
26
|
+
rb_ary_push(result, rb_float_new((float)[color blueComponent]));
|
27
|
+
rb_ary_push(result, rb_float_new((float)[color alphaComponent]));
|
28
|
+
|
29
|
+
[bitmap release];
|
30
|
+
[pool release];
|
31
|
+
|
32
|
+
return result;
|
33
|
+
}
|
34
|
+
|
35
|
+
void Init_util(void){
|
36
|
+
VALUE rb_mMac, rb_cRobot, rb_mUtil;
|
37
|
+
|
38
|
+
rb_mMac = rb_define_module("Mac");
|
39
|
+
rb_cRobot = rb_define_class_under(rb_mMac, "Robot", rb_cObject);
|
40
|
+
rb_mUtil = rb_define_module_under(rb_cRobot, "Util");
|
41
|
+
rb_define_singleton_method(rb_mUtil, "get_pixel_color", mUtil_get_pixel_color, -1);
|
42
|
+
}
|
data/lib/mac-robot.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'event_dispatcher'
|
2
|
+
require 'util'
|
2
3
|
|
3
4
|
module Mac
|
4
5
|
class Robot
|
@@ -42,6 +43,11 @@ module Mac
|
|
42
43
|
keyboard_event(keycode, 0)
|
43
44
|
end
|
44
45
|
|
46
|
+
def get_pixel_color(x, y)
|
47
|
+
color = Util.get_pixel_color(x, y)
|
48
|
+
Struct.new(:red, :green, :blue, :alpha).new(*color)
|
49
|
+
end
|
50
|
+
|
45
51
|
private
|
46
52
|
|
47
53
|
def mouse_event(button, type)
|
data/spec/mac-robot_spec.rb
CHANGED
@@ -23,4 +23,14 @@ describe Mac::Robot do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
describe 'color' do
|
28
|
+
it 'should get color from given coodinate' do
|
29
|
+
color = subject.get_pixel_color(0, 0)
|
30
|
+
color.red.should be_a_kind_of(Float)
|
31
|
+
color.green.should be_a_kind_of(Float)
|
32
|
+
color.blue.should be_a_kind_of(Float)
|
33
|
+
color.alpha.should be_a_kind_of(Float)
|
34
|
+
end
|
35
|
+
end
|
26
36
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70281658099080 !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: *70281658099080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70281658775440 !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: *70281658775440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70281658774960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,12 +43,13 @@ dependencies:
|
|
43
43
|
version: 1.8.3
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70281658774960
|
47
47
|
description: A Library to Automate User Interactions
|
48
48
|
email: youpy@buycheapviagraonlinenow.com
|
49
49
|
executables: []
|
50
50
|
extensions:
|
51
51
|
- ext/event_dispatcher/extconf.rb
|
52
|
+
- ext/util/extconf.rb
|
52
53
|
extra_rdoc_files:
|
53
54
|
- LICENSE.txt
|
54
55
|
- README.rdoc
|
@@ -64,7 +65,10 @@ files:
|
|
64
65
|
- ext/event_dispatcher/event_dispatcher.h
|
65
66
|
- ext/event_dispatcher/event_dispatcher.m
|
66
67
|
- ext/event_dispatcher/extconf.rb
|
67
|
-
- ext/
|
68
|
+
- ext/lib/mkmf.rb
|
69
|
+
- ext/util/extconf.rb
|
70
|
+
- ext/util/util.h
|
71
|
+
- ext/util/util.m
|
68
72
|
- lib/mac-robot.rb
|
69
73
|
- spec/mac-robot_spec.rb
|
70
74
|
- spec/spec_helper.rb
|
@@ -83,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
87
|
version: '0'
|
84
88
|
segments:
|
85
89
|
- 0
|
86
|
-
hash:
|
90
|
+
hash: -2418343180901678321
|
87
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
92
|
none: false
|
89
93
|
requirements:
|