special_input_device 0.0.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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/ext/special_input_device/_screen.c +25 -0
  3. data/ext/special_input_device/_screen.h +16 -0
  4. data/ext/special_input_device/_system_time.c +10 -0
  5. data/ext/special_input_device/_system_time.h +6 -0
  6. data/ext/special_input_device/_vendor__interception.c +331 -0
  7. data/ext/special_input_device/_vendor__interception.h +196 -0
  8. data/ext/special_input_device/color.c +25 -0
  9. data/ext/special_input_device/color.h +10 -0
  10. data/ext/special_input_device/extconf.rb +6 -0
  11. data/ext/special_input_device/interception_connector.c +75 -0
  12. data/ext/special_input_device/interception_connector.h +13 -0
  13. data/ext/special_input_device/keyboard.c +152 -0
  14. data/ext/special_input_device/mouse.c +1137 -0
  15. data/ext/special_input_device/point.c +17 -0
  16. data/ext/special_input_device/point.h +10 -0
  17. data/ext/special_input_device/rectangle.c +25 -0
  18. data/ext/special_input_device/rectangle.h +10 -0
  19. data/ext/special_input_device/ruby_macro.h +84 -0
  20. data/ext/special_input_device/screen.c +302 -0
  21. data/ext/special_input_device/special_input_device.c +40 -0
  22. data/ext/special_input_device/special_input_device.h +42 -0
  23. data/ext/special_input_device/win32error.c +69 -0
  24. data/ext/special_input_device/win32error.h +8 -0
  25. data/ext/special_input_device/window.c +1108 -0
  26. data/lib/special_input_device/attributes_equal_checker.rb +13 -0
  27. data/lib/special_input_device/color.rb +156 -0
  28. data/lib/special_input_device/image.rb +170 -0
  29. data/lib/special_input_device/image/bmp.rb +89 -0
  30. data/lib/special_input_device/image/error/damaged_image_error.rb +4 -0
  31. data/lib/special_input_device/image/error/image_error.rb +3 -0
  32. data/lib/special_input_device/image/error/unsupported_image_format_error.rb +4 -0
  33. data/lib/special_input_device/key_code.rb +268 -0
  34. data/lib/special_input_device/point.rb +48 -0
  35. data/lib/special_input_device/rectangle.rb +187 -0
  36. data/lib/special_input_device/special_input_device.rb +67 -0
  37. data/lib/special_input_device/table_2d.rb +157 -0
  38. data/stab/keyboard.rb +35 -0
  39. data/stab/mouse.rb +189 -0
  40. data/stab/screen.rb +56 -0
  41. data/stab/win32_error.rb +20 -0
  42. data/stab/window.rb +398 -0
  43. metadata +85 -0
@@ -0,0 +1,67 @@
1
+ # <code>SpecialInputDevice</code> is a collection of method to control the computer in the program way. It contains some
2
+ # method to simulate the input signal mainly also has some useful method to detect current state of computer.
3
+ module SpecialInputDevice
4
+
5
+ # A container of all modes.
6
+ # @see mode
7
+ module MODE
8
+ # Interception mode.
9
+ # This mode works for almost all application.
10
+ INTERCEPTION = :interception
11
+ # Win API mode.
12
+ # This mode only works for some type of application such as Windows Forms. However, this mode is a little bit
13
+ # faster.
14
+ WIN_API = :win_api
15
+ end
16
+
17
+ # A container of all color compare methods.
18
+ # @see color_compare_method
19
+ module COLOR_COMPARE_METHOD
20
+ # Calculate similarity of two colors base on their Euclidean distance in bipyramidal HSL color model.
21
+ EUCLIDEAN_METRIC_IN_HSL_BIPYRAMIDAL = :euclidean_metric_in_hsl_bipyramidal
22
+ # Calculate similarity of two colors base on their Euclidean distance in cone HSV color model.
23
+ EUCLIDEAN_METRIC_IN_HSV_CONE = :euclidean_metric_in_hsv_cone
24
+ # Calculate similarity of two colors base on their Euclidean distance in cube RGB color model.
25
+ EUCLIDEAN_METRIC_IN_RGB_CUBE = :euclidean_metric_in_rgb_cube
26
+ end
27
+
28
+ @mode = MODE::INTERCEPTION
29
+ @color_compare_method = COLOR_COMPARE_METHOD::EUCLIDEAN_METRIC_IN_HSL_BIPYRAMIDAL
30
+
31
+ class << self
32
+
33
+ # @see SpecialInputDevice::MODE
34
+ # @return [Symbol]
35
+ attr_reader(:mode)
36
+ # @see SpecialInputDevice::COLOR_COMPARE_METHOD
37
+ # @return [Symbol]
38
+ attr_reader(:color_compare_method)
39
+ # Set the simulation mode
40
+ # @param [Symbol] value
41
+ # @return [Symbol]
42
+ def mode=(value)
43
+ modes = MODE.constants(false).map { |x| MODE.const_get(x) }
44
+ raise(ArgumentError, "Undefined mode '#{value.to_s}' passed. Defined modes are [#{modes.join(', ')}].") unless modes.include?(value)
45
+ @mode = value
46
+ end
47
+
48
+ # Set the color compare method
49
+ # @param [Symbol] value
50
+ # @return [Symbol]
51
+ def color_compare_method=(value)
52
+ color_compare_methods = COLOR_COMPARE_METHOD.constants(false).map { |x| COLOR_COMPARE_METHOD.const_get(x) }
53
+ raise(ArgumentError, "Undefined method '#{value.to_s}' passed. Defined methods are [#{color_compare_methods.join(', ')}].") unless color_compare_methods.include?(value)
54
+ @color_compare_method = value
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ require_relative('attributes_equal_checker')
62
+ require_relative('color')
63
+ require_relative('image')
64
+ require_relative('key_code')
65
+ require_relative('point')
66
+ require_relative('rectangle')
67
+ require_relative('table_2d')
@@ -0,0 +1,157 @@
1
+ # <code>Table2D</code> object is a container which act like a two dimensional array.
2
+ class SpecialInputDevice::Table2D
3
+
4
+ include(Enumerable)
5
+
6
+ # @return [Fixnum] the width of table
7
+ attr_reader(:width)
8
+
9
+ # @return [Fixnum] the height of table
10
+ attr_reader(:height)
11
+
12
+ # @!scope class
13
+ # @overload new(width, height, default = nil, &block)
14
+ # @param [Integer] width the width of table
15
+ # @param [Integer] height the height of table
16
+ # @param [Object] default the default value
17
+ # @param [Proc] block initializer of the table
18
+ # @yield [x, y] initializer of the table
19
+ # @yieldparam [Integer] x the x coordinate
20
+ # @yieldparam [Integer] y the y coordinate
21
+ # @yieldreturn [Object] the value to be stored
22
+ def initialize(width, height, default = nil, &block)
23
+ @width = width
24
+ @height = height
25
+ @data = Array.new(width) do |x0|
26
+ Array.new(height) do |x1|
27
+ value = if block
28
+ yield x0, x1
29
+ else
30
+ default
31
+ end
32
+ validate(x0, x1, value)
33
+ end
34
+ end
35
+ end
36
+
37
+ # @param [Integer] x the x coordinate
38
+ # @param [Integer] y the y coordinate
39
+ # @return [Object] the object at the specific coordinate
40
+ def [](x, y)
41
+ raise(RangeError, "The table only has #{@height} row. The row at #{y} cannot be accessed.") unless (-@height...@height).include?(y)
42
+ raise(RangeError, "The table only has #{@width} column. The column at #{x} cannot be accessed") unless (-@width...@width).include?(x)
43
+ @data[x][y]
44
+ end
45
+
46
+ # @param [Integer] x the x coordinate
47
+ # @param [Integer] y the y coordinate
48
+ # @param [Object] value the new value
49
+ # @return [Object] the new value
50
+ def []=(x, y, value)
51
+ raise(RangeError, "The table only has #{@height} row. The row at #{y} cannot be accessed.") unless (-@height...@height).include?(y)
52
+ raise(RangeError, "The table only has #{@width} column. The column at #{x} cannot be accessed") unless (-@width...@width).include?(x)
53
+ validate(x, y, value)
54
+ @data[x][y] = value
55
+ end
56
+
57
+ # @param [Integer] x the x coordinate
58
+ # @param [Integer] y the y coordinate
59
+ # @return [Object] the object at the specific coordinate
60
+ def try_get(x, y)
61
+ self[x, y] if (-@width...@width).include?(x) && (-@height...@height).include?(y)
62
+ end
63
+
64
+ # @param [Integer] x the x coordinate
65
+ # @param [Integer] y the y coordinate
66
+ # @param [Object] value the new value
67
+ # @return [Object] the new value
68
+ def try_set(x, y, value)
69
+ self[x, y] = value if (-@width...@width).include?(x) && (-@height...@height).include?(y)
70
+ end
71
+
72
+ # @param [Proc] block the action
73
+ # @yield [value, position] the action
74
+ # @yieldparam [Object] value the value
75
+ # @yieldparam [SpecialInputDevice::Point] position the position of the value
76
+ # @yieldreturn [Object] value will be ignored
77
+ # @return [Enumerator, SpecialInputDevice::Table2D] a Enumerator if no block gavin, self otherwise.
78
+ def each(&block)
79
+ if block
80
+ @data.each.with_index do |v0, i0|
81
+ v0.each.with_index do |v1, i1|
82
+ yield v1, SpecialInputDevice::Point.new(i0, i1)
83
+ end
84
+ end
85
+ self
86
+ else
87
+ Enumerator.new(self)
88
+ end
89
+ end
90
+
91
+ # @param [Proc] block the action
92
+ # @yield [row] the action
93
+ # @yieldparam [Array<Object>] row the row
94
+ # @yieldreturn [Object] value will be ignored
95
+ # @return [Enumerator, SpecialInputDevice::Table2D] a Enumerator if no block gavin, self otherwise.
96
+ def each_row(&block)
97
+ enumerator = :zip.to_proc.call(*@data).each(&block)
98
+ block ? self : enumerator
99
+ end
100
+
101
+ # @param [Proc] block the action
102
+ # @yield [column] the action
103
+ # @yieldparam [Array<Object>] column the column
104
+ # @yieldreturn [Object] value will be ignored
105
+ # @return [Enumerator, SpecialInputDevice::Table2D] a Enumerator if no block gavin, self otherwise.
106
+ def each_column(&block)
107
+ enumerator = @data.each(&block)
108
+ block ? self : enumerator
109
+ end
110
+
111
+ # @param [Integer] y the y coordinate
112
+ # @param [Proc] block the action
113
+ # @yield [value] the action
114
+ # @yieldparam [Object] value the value
115
+ # @yieldreturn [Object] value will be ignored
116
+ # @return [Enumerator, SpecialInputDevice::Table2D] a Enumerator if no block gavin, self otherwise.
117
+ def each_in_row(y, &block)
118
+ raise(RangeError, "The table only has #{@height} row. The row at #{y} cannot be accessed.") unless (-@height...@height).include?(y)
119
+ enumerator = @data.map { |x| x[y] }.each(&block)
120
+ block ? self : enumerator
121
+ end
122
+
123
+ # @param [Integer] x the x coordinate
124
+ # @param [Proc] block the action
125
+ # @yield [value] the action
126
+ # @yieldparam [Object] value the value
127
+ # @yieldreturn [Object] value will be ignored
128
+ # @return [Enumerator, SpecialInputDevice::Table2D] a Enumerator if no block gavin, self otherwise.
129
+ def each_in_column(x, &block)
130
+ raise(RangeError, "The table only has #{@width} column. The column at #{x} cannot be accessed") unless (-@width...@width).include?(x)
131
+ enumerator = @data[x].each(&block)
132
+ block ? self : enumerator
133
+ end
134
+
135
+ # @param [Proc] block the mapper
136
+ # @yield [value, position] the mapper
137
+ # @yieldparam [Object] value the value
138
+ # @yieldparam [SpecialInputDevice::Point] position an array included x and y
139
+ # @yieldreturn [Object] the value to be stored
140
+ # @return [Enumerator, SpecialInputDevice::Table2D] a Enumerator if no block gavin, self otherwise.
141
+ def map(&block)
142
+ (0...width).each { |x0| (0...height).each { |x1| self[x0, x1] = yield self[x0, x1], SpecialInputDevice::Point.new(x0, x1) } }
143
+ block ? self : Enumerator.new(self, :map)
144
+ end
145
+
146
+ # Override this method if validation is needed. In this method, raise an <code>Exception</code> if it is not valid.
147
+ # @param [Integer] x the x coordinate
148
+ # @param [Integer] y the y coordinate
149
+ # @param [Object] value the object at the specific coordinate
150
+ # @return [Object] the value to be stored
151
+ def validate(x, y, value)
152
+ value
153
+ end
154
+
155
+ protected(:validate)
156
+
157
+ end
data/stab/keyboard.rb ADDED
@@ -0,0 +1,35 @@
1
+ # noinspection ALL
2
+ module SpecialInputDevice::Keyboard
3
+
4
+ class << self
5
+
6
+ # Simulate holding the specified key down.
7
+ # @param [Integer] key_code virtual key code. Use a value of constant in {SpecialInputDevice::KeyCode}.
8
+ # @return [Module] self
9
+ # @see SpecialInputDevice::Window#key_hold
10
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
11
+ def hold(key_code)
12
+ # This is a stub, used for indexing
13
+ end
14
+
15
+ # Simulate pressing the specified key.
16
+ # @param [Integer] key_code virtual key code. Use a value of constant in {SpecialInputDevice::KeyCode}.
17
+ # @return [Module] self
18
+ # @see SpecialInputDevice::Window#key_press
19
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
20
+ def press(key_code)
21
+ # This is a stub, used for indexing
22
+ end
23
+
24
+ # Simulate releasing the specified key.
25
+ # @param [Integer] key_code virtual key code. Use a value of constant in {SpecialInputDevice::KeyCode}.
26
+ # @return [Module] self
27
+ # @see SpecialInputDevice::Window#key_release
28
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
29
+ def release(key_code)
30
+ # This is a stub, used for indexing
31
+ end
32
+
33
+ end
34
+
35
+ end
data/stab/mouse.rb ADDED
@@ -0,0 +1,189 @@
1
+ # noinspection ALL
2
+ module SpecialInputDevice::Mouse
3
+
4
+ class << self
5
+
6
+ # Lock the mouse.
7
+ # @return [Module] self
8
+ def lock
9
+ # This is a stub, used for indexing
10
+ end
11
+
12
+ # Unlock the mouse.
13
+ # @return [Module] self
14
+ def unlock
15
+ # This is a stub, used for indexing
16
+ end
17
+
18
+ # @return [SpecialInputDevice::Point] the point of cursor position
19
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
20
+ def cursor_position
21
+ # This is a stub, used for indexing
22
+ end
23
+
24
+ # Move the cursor position relative to current position.
25
+ # @param [Integer] x the amount of horizontal motion specified as the number of pixels.
26
+ # @param [Integer] y the amount of vertical motion specified as the number of pixels.
27
+ # @return [Module] self
28
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
29
+ def move_relatively(x, y)
30
+ # This is a stub, used for indexing
31
+ end
32
+
33
+ # Move the cursor position relative to the upper-left corner of primary screen.
34
+ # @param [Integer] x the x-coordinate of position specified as the number of pixels.
35
+ # @param [Integer] y the y-coordinate of position specified as the number of pixels.
36
+ # @return [Module] self
37
+ # @see SpecialInputDevice::Screen.primary_screen
38
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
39
+ def move_to_primary(x, y)
40
+ # This is a stub, used for indexing
41
+ end
42
+
43
+ # Move the cursor position relative to the upper-left corner of virtual screen. If the position of virtual screen is
44
+ # inaccessible, the cursor will move to the closest point to the specified position.
45
+ # @param [Integer] x the x-coordinate of position specified as the number of pixels.
46
+ # @param [Integer] y the y-coordinate of position specified as the number of pixels.
47
+ # @return [Module] self
48
+ # @see SpecialInputDevice::Screen.virtual_screen
49
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
50
+ def move_to_virtual(x, y)
51
+ # This is a stub, used for indexing
52
+ end
53
+
54
+ # Simulate clicking the left button on the mouse.
55
+ # @return [Module] self
56
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
57
+ def left_click
58
+ # This is a stub, used for indexing
59
+ end
60
+
61
+ # Simulate holding the left button on the mouse down.
62
+ # @return [Module] self
63
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
64
+ def left_down
65
+ # This is a stub, used for indexing
66
+ end
67
+
68
+ # Simulate releasing the left button on the mouse.
69
+ # @return [Module] self
70
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
71
+ def left_up
72
+ # This is a stub, used for indexing
73
+ end
74
+
75
+ # Simulate clicking the right button on the mouse.
76
+ # @return [Module] self
77
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
78
+ def right_click
79
+ # This is a stub, used for indexing
80
+ end
81
+
82
+ # Simulate holding the right button on the mouse down.
83
+ # @return [Module] self
84
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
85
+ def right_down
86
+ # This is a stub, used for indexing
87
+ end
88
+
89
+ # Simulate releasing the right button on the mouse.
90
+ # @return [Module] self
91
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
92
+ def right_up
93
+ # This is a stub, used for indexing
94
+ end
95
+
96
+ # Simulate clicking the middle button on the mouse.
97
+ # @return [Module] self
98
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
99
+ def middle_click
100
+ # This is a stub, used for indexing
101
+ end
102
+
103
+ # Simulate holding the middle button on the mouse down.
104
+ # @return [Module] self
105
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
106
+ def middle_down
107
+ # This is a stub, used for indexing
108
+ end
109
+
110
+ # Simulate releasing the middle button on the mouse.
111
+ # @return [Module] self
112
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
113
+ def middle_up
114
+ # This is a stub, used for indexing
115
+ end
116
+
117
+ # Simulate clicking the x1 button on the mouse.
118
+ # @return [Module] self
119
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
120
+ def x1_click
121
+ # This is a stub, used for indexing
122
+ end
123
+
124
+ # Simulate holding the x1 button on the mouse down.
125
+ # @return [Module] self
126
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
127
+ def x1_down
128
+ # This is a stub, used for indexing
129
+ end
130
+
131
+ # Simulate releasing the x1 button on the mouse.
132
+ # @return [Module] self
133
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
134
+ def x1_up
135
+ # This is a stub, used for indexing
136
+ end
137
+
138
+ # Simulate clicking the x2 button on the mouse.
139
+ # @return [Module] self
140
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
141
+ def x2_click
142
+ # This is a stub, used for indexing
143
+ end
144
+
145
+ # Simulate holding the x2 button on the mouse down.
146
+ # @return [Module] self
147
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
148
+ def x2_down
149
+ # This is a stub, used for indexing
150
+ end
151
+
152
+ # Simulate releasing the x2 button on the mouse.
153
+ # @return [Module] self
154
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
155
+ def x2_up
156
+ # This is a stub, used for indexing
157
+ end
158
+
159
+ # Simulate wheeling the scroll backward.
160
+ # @return [Module] self
161
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
162
+ def scroll_wheel_backward
163
+ # This is a stub, used for indexing
164
+ end
165
+
166
+ # Simulate wheeling the scroll forward.
167
+ # @return [Module] self
168
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
169
+ def scroll_wheel_forward
170
+ # This is a stub, used for indexing
171
+ end
172
+
173
+ # Simulate wheeling the scroll to left hand side.
174
+ # @return [Module] self
175
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
176
+ def scroll_wheel_to_left
177
+ # This is a stub, used for indexing
178
+ end
179
+
180
+ # Simulate wheeling the scroll to right hand side.
181
+ # @return [Module] self
182
+ # @see https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310.aspx Windows Dev Center - SendInput function
183
+ def scroll_wheel_to_right
184
+ # This is a stub, used for indexing
185
+ end
186
+
187
+ end
188
+
189
+ end