win 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +18 -19
- data/VERSION +1 -1
- data/lib/win/dde.rb +147 -88
- data/lib/win/gui/dialog.rb +35 -1
- data/lib/win/gui/input.rb +128 -93
- data/lib/win/gui/message.rb +365 -5
- data/lib/win/gui/{convenience.rb → window/window.rb} +12 -67
- data/lib/win/gui/window.rb +338 -219
- data/lib/win/gui.rb +1 -2
- data/lib/win/library.rb +0 -2
- data/spec/spec_helper.rb +4 -4
- data/spec/win/gui/dialog_spec.rb +22 -7
- data/spec/win/gui/input_spec.rb +30 -0
- data/spec/win/gui/message_spec.rb +0 -7
- data/spec/win/gui/{convenience_spec.rb → window/window_spec.rb} +13 -61
- data/spec/win/gui/window_spec.rb +30 -4
- data/spec/win/library_spec.rb +0 -27
- data/win.gemspec +5 -5
- metadata +5 -5
data/lib/win/gui/input.rb
CHANGED
@@ -7,6 +7,11 @@ module Win
|
|
7
7
|
module Input
|
8
8
|
include Win::Library
|
9
9
|
|
10
|
+
# Internal constants:
|
11
|
+
|
12
|
+
# Key event delay
|
13
|
+
KEY_DELAY = 0.00001
|
14
|
+
|
10
15
|
# Windows keyboard-related Constants:
|
11
16
|
|
12
17
|
# Key down keyboard event (the key is being depressed)
|
@@ -132,115 +137,123 @@ module Win
|
|
132
137
|
# The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate
|
133
138
|
# a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
|
134
139
|
#
|
135
|
-
#
|
140
|
+
# <b> !! Windows NT/2000/XP/Vista:This function has been superseded. Use SendInput instead. </b>
|
136
141
|
#
|
137
|
-
# Syntax
|
142
|
+
# [*Syntax*] VOID keybd_event( BYTE bVk, BYTE bScan, DWORD dwFlags, PTR dwExtraInfo);
|
138
143
|
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# dwExtraInfo [L] -[in] Specifies an additional value associated with the key stroke.
|
144
|
+
# bVk:: [in] Specifies a virtual-key code. The code must be a value in the range 1 to 254.
|
145
|
+
# For a complete list, see Virtual-Key Codes.
|
146
|
+
# bScan:: [in] Specifies a hardware scan code for the key.
|
147
|
+
# dwFlags:: [in] Specifies various aspects of function operation. This parameter can be
|
148
|
+
# one or more of the following values:
|
149
|
+
# KEYEVENTF_EXTENDEDKEY, KEYEVENTF_KEYUP, KEYEVENTF_KEYDOWN
|
150
|
+
# dwExtraInfo:: [in] Specifies an additional value associated with the key stroke.
|
147
151
|
#
|
148
|
-
#
|
152
|
+
# *Returns*:: nothing
|
153
|
+
# ---
|
154
|
+
# *Remarks*:
|
155
|
+
# - An application can simulate a press of the PRINTSCRN key in order to obtain a screen snapshot
|
156
|
+
# and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT.
|
149
157
|
#
|
150
|
-
#
|
151
|
-
#
|
158
|
+
# - Windows NT/2000/XP: The keybd_event function can toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys.
|
159
|
+
# - Windows 95/98/Me: The keybd_event function can toggle only the CAPS LOCK and SCROLL LOCK keys.
|
152
160
|
#
|
153
|
-
#
|
154
|
-
#
|
161
|
+
# :call-seq:
|
162
|
+
# keybd_event( virtual_key, scan_code, flags, extra_info )
|
155
163
|
#
|
156
|
-
function
|
164
|
+
function :keybd_event, [:char, :char, :ulong, :ulong], :void
|
157
165
|
|
158
166
|
##
|
159
167
|
# The mouse_event function synthesizes mouse motion and button clicks.
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
# MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP,
|
174
|
-
# MOUSEEVENTF_XUP
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
# mouse
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
220
|
-
#
|
221
|
-
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
|
168
|
+
#
|
169
|
+
# <b> !! Windows NT/2000/XP/Vista:This function has been superseded. Use SendInput instead. </b>
|
170
|
+
#
|
171
|
+
# [*Syntax*] VOID mouse_event( DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo );
|
172
|
+
#
|
173
|
+
# dwFlags:: [in] Specifies various aspects of mouse motion and button clicking. This parameter can be certain
|
174
|
+
# combinations of the following values. The values that specify mouse button status are set to indicate
|
175
|
+
# changes in status, not ongoing conditions. For example, if the left mouse button is pressed and
|
176
|
+
# held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent
|
177
|
+
# motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released. You cannot
|
178
|
+
# specify both MOUSEEVENTF_WHEEL and either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP simultaneously,
|
179
|
+
# because they both require use of the dwData field:
|
180
|
+
# MOUSEEVENTF_ABSOLUTE, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP,
|
181
|
+
# MOUSEEVENTF_RIGHTDOWN, MOUSEEVENTF_RIGHTUP, MOUSEEVENTF_MIDDLEDOWN, MOUSEEVENTF_MIDDLEUP,
|
182
|
+
# MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, MOUSEEVENTF_XUP
|
183
|
+
# dx:: [in] Specifies the mouse's absolute position along the x-axis or its amount of motion since the
|
184
|
+
# last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is
|
185
|
+
# specified as the mouse's actual x-coordinate; relative data is specified as the number of mickeys moved.
|
186
|
+
# A mickey is the amount that a mouse has to move for it to report that it has moved.
|
187
|
+
# dy:: [in] Specifies the mouse's absolute position along the y-axis or its amount of motion since the
|
188
|
+
# last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is
|
189
|
+
# specified as the mouse's actual y-coordinate; relative data is specified as the number of mickeys moved.
|
190
|
+
# dwData:: [in]
|
191
|
+
# - If dwFlags contains MOUSEEVENTF_WHEEL, then data specifies the amount of wheel movement.
|
192
|
+
# A positive value indicates that the wheel was rotated forward, away from the user; a negative value
|
193
|
+
# indicates that the wheel was rotated backward, toward the user. One wheel click is defined as
|
194
|
+
# WHEEL_DELTA, which is 120.
|
195
|
+
# - If dwFlags contains MOUSEEVENTF_WHHEEL, then data specifies the amount of
|
196
|
+
# wheel movement. A positive value indicates that the wheel was rotated to the right; a negative value
|
197
|
+
# indicates that the wheel was rotated to the left. One wheel click is defined as WHEEL_DELTA (= 120).
|
198
|
+
# - Windows 2000/XP: If flags contains MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, then data specifies which
|
199
|
+
# X buttons were pressed or released. This value may be any combination of the following flags.
|
200
|
+
# - If flags is not MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then data should be zero.
|
201
|
+
# XBUTTON1 - Set if the first X button was pressed or released.
|
202
|
+
# XBUTTON2 - Set if the second X button was pressed or released.
|
203
|
+
# dwExtraInfo:: [in] Specifies an additional value associated with the mouse event. An application
|
204
|
+
# calls GetMessageExtraInfo to obtain this extra information.
|
205
|
+
# <b>NO Return Value</b>
|
206
|
+
# ---
|
207
|
+
# *Remarks*:
|
208
|
+
# - If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about
|
209
|
+
# that motion. The information is specified as absolute or relative integer values.
|
210
|
+
# - If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between
|
211
|
+
# 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps
|
212
|
+
# onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.
|
213
|
+
# - If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the
|
214
|
+
# last mouse event was generated (the last reported position). Positive values mean the mouse moved right
|
215
|
+
# (or down); negative values mean the mouse moved left (or up). Relative mouse motion is subject to the
|
216
|
+
# settings for mouse speed and acceleration level. An end user sets these values using the Mouse application
|
217
|
+
# in Control Panel. An application obtains and sets these values with the SystemParametersInfo function.
|
218
|
+
# - The system applies two tests to the specified relative mouse motion when applying acceleration. If the
|
219
|
+
# specified distance along either the x or y axis is greater than the first mouse threshold value, and the
|
220
|
+
# mouse acceleration level is not zero, the operating system doubles the distance. If the specified distance
|
221
|
+
# along either the x- or y-axis is greater than the second mouse threshold value, and the mouse acceleration
|
222
|
+
# level is equal to two, the operating system doubles the distance that resulted from applying the first
|
223
|
+
# threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion
|
224
|
+
# along the x- or y-axis by up to four times.
|
225
|
+
# - Once acceleration has been applied, the system scales the resultant value by the desired mouse speed.
|
226
|
+
# Mouse speed can range from 1 (slowest) to 20 (fastest) and represents how much the pointer moves based
|
227
|
+
# on the distance the mouse moves. The default value is 10, which results in no additional modification
|
228
|
+
# to the mouse motion.
|
229
|
+
# - The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also
|
230
|
+
# used by applications that need to obtain more information from the mouse than its position and button state.
|
231
|
+
# For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can
|
232
|
+
# write a DLL that communicates directly to the tablet hardware, obtains the extra information, and saves it
|
233
|
+
# in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with,
|
234
|
+
# in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application
|
235
|
+
# needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL
|
236
|
+
# returns the extra information.
|
237
|
+
#
|
238
|
+
# :call-seq:
|
239
|
+
# mouse_event( flags, dx, dy, data, extra_info )
|
240
|
+
#
|
241
|
+
function :mouse_event, [:ulong, :ulong, :ulong, :ulong, :ulong, ], :void
|
228
242
|
|
229
243
|
##
|
230
244
|
# SetCursorPos Function moves the cursor to the specified screen coordinates. If the new coordinates are not
|
231
245
|
# within the screen rectangle set by the most recent ClipCursor function call, the system automatically adjusts
|
232
246
|
# the coordinates so that the cursor stays within the rectangle.
|
233
247
|
#
|
234
|
-
# Syntax
|
248
|
+
# [*Syntax*] BOOL SetCursorPos( int X, int Y );
|
235
249
|
#
|
236
|
-
#
|
237
|
-
#
|
238
|
-
# Y (i) - [in] Specifies the new y-coordinate of the cursor, in screen coordinates.
|
250
|
+
# X:: [in] Specifies the new x-coordinate of the cursor, in screen coordinates.
|
251
|
+
# Y:: [in] Specifies the new y-coordinate of the cursor, in screen coordinates.
|
239
252
|
#
|
240
|
-
#
|
241
|
-
# Enhanced to return true/false instead of nonzero/zero
|
242
|
-
#
|
243
|
-
# Remarks
|
253
|
+
# *Returns*:: Nonzero(*true*) if successful or zero(*false*) otherwise. To get extended error information,
|
254
|
+
# call GetLastError. Enhanced to return true/false instead of nonzero/zero
|
255
|
+
# ---
|
256
|
+
# *Remarks*: The cursor is a shared resource. A window should move the cursor only when the cursor is in the
|
244
257
|
# window's client area. The calling process must have WINSTA_WRITEATTRIBUTES access to the window station.
|
245
258
|
# The input desktop must be the current desktop when you call SetCursorPos. Call OpenInputDesktop to determine
|
246
259
|
# whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned
|
@@ -249,7 +262,29 @@ module Win
|
|
249
262
|
# :call-seq:
|
250
263
|
# success = set_cursor_pos(x,y)
|
251
264
|
#
|
252
|
-
function :SetCursorPos, [:int, :int], :
|
265
|
+
function :SetCursorPos, [:int, :int], :int, boolean: true
|
266
|
+
|
267
|
+
# Convenience methods
|
268
|
+
|
269
|
+
##
|
270
|
+
# Emulates combinations of (any amount of) keys pressed one after another (Ctrl+Alt+P) and then released
|
271
|
+
# *keys should be a sequence of a virtual-key codes. The codes must be a value in the range 1 to 254.
|
272
|
+
# For a complete list, see msdn:Virtual Key Codes.
|
273
|
+
def keystroke(*keys)
|
274
|
+
return if keys.empty?
|
275
|
+
keybd_event keys.first, 0, KEYEVENTF_KEYDOWN, 0
|
276
|
+
sleep KEY_DELAY
|
277
|
+
keystroke *keys[1..-1]
|
278
|
+
sleep KEY_DELAY
|
279
|
+
keybd_event keys.first, 0, KEYEVENTF_KEYUP, 0
|
280
|
+
end
|
281
|
+
|
282
|
+
# types text message into window holding the focus
|
283
|
+
def type_in(message)
|
284
|
+
message.scan(/./m) do |char|
|
285
|
+
keystroke(*char.to_vkeys)
|
286
|
+
end
|
287
|
+
end
|
253
288
|
end
|
254
289
|
end
|
255
290
|
end
|