mac-robot 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,18 +8,26 @@ A Library to Automate User Interactions
8
8
 
9
9
  robot = Mac::Robot.new
10
10
 
11
- === Automate Mouse
11
+ === Automate mouse
12
12
 
13
13
  robot.mouse_press
14
14
  robot.mouse_move(250, 250)
15
15
  robot.mouse_release
16
16
 
17
- === Automate Keyboard
17
+ === Automate keyboard
18
18
 
19
19
  [0x04, 0x0e, 0x25, 0x25, 0x1f].each do |keycode|
20
- subject.key_press(keycode)
21
- subject.key_release(keycode)
20
+ robot.key_press(keycode)
21
+ robot.key_release(keycode)
22
22
  end
23
+
24
+ === Get color of given pixel on screen
25
+
26
+ color = robot.get_pixel_color(10, 20)
27
+ color.red
28
+ color.green
29
+ color.blue
30
+ color.alpha
23
31
 
24
32
  == Contributing to mac-robot
25
33
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/ext/util/util.m CHANGED
@@ -32,6 +32,21 @@ static VALUE mUtil_get_pixel_color(int argc, VALUE *argv, VALUE self)
32
32
  return result;
33
33
  }
34
34
 
35
+ static VALUE mUtil_get_display_pixel_size(int argc, VALUE *argv, VALUE self)
36
+ {
37
+ int width, height;
38
+ VALUE result;
39
+
40
+ width = (int)CGDisplayPixelsWide((CGDirectDisplayID)0);
41
+ height = (int)CGDisplayPixelsHigh((CGDirectDisplayID)0);
42
+
43
+ result = rb_ary_new();
44
+ rb_ary_push(result, INT2NUM(width));
45
+ rb_ary_push(result, INT2NUM(height));
46
+
47
+ return result;
48
+ }
49
+
35
50
  void Init_util(void){
36
51
  VALUE rb_mMac, rb_cRobot, rb_mUtil;
37
52
 
@@ -39,4 +54,5 @@ void Init_util(void){
39
54
  rb_cRobot = rb_define_class_under(rb_mMac, "Robot", rb_cObject);
40
55
  rb_mUtil = rb_define_module_under(rb_cRobot, "Util");
41
56
  rb_define_singleton_method(rb_mUtil, "get_pixel_color", mUtil_get_pixel_color, -1);
57
+ rb_define_singleton_method(rb_mUtil, "get_display_pixel_size", mUtil_get_display_pixel_size, -1);
42
58
  }
data/lib/mac-robot.rb CHANGED
@@ -3,6 +3,9 @@ require 'util'
3
3
 
4
4
  module Mac
5
5
  class Robot
6
+ class Error < StandardError; end
7
+ class OutOfResolution < Error; end
8
+
6
9
  attr_reader :x, :y
7
10
 
8
11
  BUTTONS = {
@@ -44,10 +47,17 @@ module Mac
44
47
  end
45
48
 
46
49
  def get_pixel_color(x, y)
50
+ raise OutOfResolution if x < 0 || y < 0
51
+ raise OutOfResolution if display_pixel_size.width < x || display_pixel_size.height < y
52
+
47
53
  color = Util.get_pixel_color(x, y)
48
54
  Struct.new(:red, :green, :blue, :alpha).new(*color)
49
55
  end
50
56
 
57
+ def display_pixel_size
58
+ @screen ||= Struct.new(:width, :height).new(*Util.get_display_pixel_size)
59
+ end
60
+
51
61
  private
52
62
 
53
63
  def mouse_event(button, type)
data/mac-robot.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "mac-robot"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["youpy"]
12
+ s.date = "2012-04-10"
13
+ s.description = "A Library to Automate User Interactions"
14
+ s.email = "youpy@buycheapviagraonlinenow.com"
15
+ s.extensions = ["ext/event_dispatcher/extconf.rb", "ext/util/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "ext/event_dispatcher/event_dispatcher.h",
30
+ "ext/event_dispatcher/event_dispatcher.m",
31
+ "ext/event_dispatcher/extconf.rb",
32
+ "ext/lib/mkmf.rb",
33
+ "ext/util/extconf.rb",
34
+ "ext/util/util.h",
35
+ "ext/util/util.m",
36
+ "lib/mac-robot.rb",
37
+ "spec/mac-robot_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+ s.homepage = "http://github.com/youpy/mac-robot"
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.10"
44
+ s.summary = "A Library to Automate User Interactions"
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
51
+ s.add_development_dependency(%q<bundler>, [">= 0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ else
54
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
55
+ s.add_dependency(%q<bundler>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
60
+ s.add_dependency(%q<bundler>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
62
+ end
63
+ end
64
+
@@ -25,12 +25,24 @@ describe Mac::Robot do
25
25
  end
26
26
 
27
27
  describe 'color' do
28
- it 'should get color from given coodinate' do
28
+ it 'should get color from given coordinate' do
29
29
  color = subject.get_pixel_color(0, 0)
30
30
  color.red.should be_a_kind_of(Float)
31
31
  color.green.should be_a_kind_of(Float)
32
32
  color.blue.should be_a_kind_of(Float)
33
33
  color.alpha.should be_a_kind_of(Float)
34
34
  end
35
+
36
+ it 'should raise if given coordinate is out of resolution' do
37
+ [9999, -1].each do |p|
38
+ lambda {
39
+ subject.get_pixel_color(p, 0)
40
+ }.should raise_error(Mac::Robot::OutOfResolution)
41
+
42
+ lambda {
43
+ subject.get_pixel_color(0, p)
44
+ }.should raise_error(Mac::Robot::OutOfResolution)
45
+ end
46
+ end
35
47
  end
36
48
  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.2.0
4
+ version: 0.2.1
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-30 00:00:00.000000000 Z
12
+ date: 2012-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70281658099080 !ruby/object:Gem::Requirement
16
+ requirement: &70137836188740 !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: *70281658099080
24
+ version_requirements: *70137836188740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70281658775440 !ruby/object:Gem::Requirement
27
+ requirement: &70137836188160 !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: *70281658775440
35
+ version_requirements: *70137836188160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70281658774960 !ruby/object:Gem::Requirement
38
+ requirement: &70137836187600 !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: *70281658774960
46
+ version_requirements: *70137836187600
47
47
  description: A Library to Automate User Interactions
48
48
  email: youpy@buycheapviagraonlinenow.com
49
49
  executables: []
@@ -70,6 +70,7 @@ files:
70
70
  - ext/util/util.h
71
71
  - ext/util/util.m
72
72
  - lib/mac-robot.rb
73
+ - mac-robot.gemspec
73
74
  - spec/mac-robot_spec.rb
74
75
  - spec/spec_helper.rb
75
76
  homepage: http://github.com/youpy/mac-robot
@@ -87,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
88
  version: '0'
88
89
  segments:
89
90
  - 0
90
- hash: -2418343180901678321
91
+ hash: -4196632184157000658
91
92
  required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  none: false
93
94
  requirements: