lib/win32/autogui/input.rb in win32-autogui-0.4.0 vs lib/win32/autogui/input.rb in win32-autogui-0.4.1
- old
+ new
@@ -117,22 +117,22 @@
VK_LCONTROL = 0xa2
VK_RCONTROL = 0xa3
VK_LMENU = 0xa4
VK_RMENU = 0xa5
- VK_OEM_1 = 0xba
+ VK_OEM_1 = 0xba # US ";:"
VK_OEM_PLUS = 0xbb
VK_OEM_COMMA = 0xbc
VK_OEM_MINUS = 0xbd
VK_OEM_PERIOD = 0xbe
- VK_OEM_2 = 0xbf
- VK_OEM_3 = 0xc0 # US '~' key
- VK_OEM_4 = 0xdb
- VK_OEM_5 = 0xdc # US '\' key
- VK_OEM_6 = 0xdd
- VK_OEM_7 = 0xde # US quotes key
- VK_OEM_8 = 0xdf
+ VK_OEM_2 = 0xbf # US "/?"
+ VK_OEM_3 = 0xc0 # US '`~'
+ VK_OEM_4 = 0xdb # US "[{"
+ VK_OEM_5 = 0xdc # US '\|'
+ VK_OEM_6 = 0xdd # US ']}'
+ VK_OEM_7 = 0xde # US quotes
+ VK_OEM_8 = 0xdf # none
# delay in seconds between keystrokes
KEYBD_KEYDELAY = 0.050
# keybd_event
@@ -149,28 +149,28 @@
# Send keystroke to the focused window, keystrokes are virtual keycodes
#
# @example send 2+2<CR>
#
- # keystroke(VK_2, VK_ADD, VK_2, VK_RETURN)
+ # keystroke(VK_2, VK_ADD, VK_2, VK_RETURN)
#
def keystroke(*keys)
return if keys.empty?
-
+
keybd_event keys.first, 0, KEYBD_EVENT_KEYDOWN, 0
sleep KEYBD_KEYDELAY
keystroke *keys[1..-1]
sleep KEYBD_KEYDELAY
- keybd_event keys.first, 0, KEYBD_EVENT_KEYUP, 0
+ keybd_event keys.first, 0, KEYBD_EVENT_KEYUP, 0
end
- # String together keystrokes, simulates the user typing.
+ # String together keystrokes, simulates the user typing.
#
# Note: This method can be slow for large strings. Consider using
- # the clipboard instead.
+ # the clipboard instead.
#
- # @see Clipboard
+ # @see Clipboard
#
# @example send 2+2<CR>
#
# type_in("2+2\n")
#
@@ -191,11 +191,11 @@
def char_to_virtual_keycode(char)
unless char.size == 1
raise "virtual keycode conversion is for single characters only"
end
-
+
code = char.unpack('U')[0]
case char
when '0'..'9'
[code - ?0 + 0x30]
@@ -215,24 +215,65 @@
[VK_OEM_PERIOD]
when '-'
[VK_OEM_MINUS]
when '_'
[VK_SHIFT, VK_OEM_MINUS]
- when ':'
- [VK_SHIFT, VK_OEM_1]
+
when ';'
[VK_OEM_1]
+ when ':'
+ [VK_SHIFT, VK_OEM_1]
+ when '/'
+ [VK_OEM_2]
+ when '?'
+ [VK_SHIFT, VK_OEM_2]
+ when '`'
+ [VK_OEM_3]
+ when '~'
+ [VK_SHIFT, VK_OEM_3]
+ when '['
+ [VK_OEM_4]
+ when '{'
+ [VK_SHIFT, VK_OEM_4]
+ when '\\'
+ [VK_OEM_5]
+ when '|'
+ [VK_SHIFT, VK_OEM_5]
+ when ']'
+ [VK_OEM_6]
+ when '}'
+ [VK_SHIFT, VK_OEM_6]
when '\''
[VK_OEM_7]
when '\"'
[VK_SHIFT, VK_OEM_7]
- when "\\"
- [VK_OEM_5]
+
+ when '!'
+ [VK_SHIFT, VK_1]
+ when '@'
+ [VK_SHIFT, VK_2]
+ when '#'
+ [VK_SHIFT, VK_3]
+ when '$'
+ [VK_SHIFT, VK_4]
+ when '%'
+ [VK_SHIFT, VK_5]
+ when '^'
+ [VK_SHIFT, VK_6]
+ when '&'
+ [VK_SHIFT, VK_7]
+ when '*'
+ [VK_SHIFT, VK_8]
+ when '('
+ [VK_SHIFT, VK_9]
+ when ')'
+ [VK_SHIFT, VK_0]
+
when "\n"
[VK_RETURN]
else
raise "No conversion exists for character #{char}"
end
- end
+ end
end
end