P. 1
VB6.0 SendKeys Function Tutorial

VB6.0 SendKeys Function Tutorial

|Views: 2,196|Likes:

More info:

Published by: Sandipon Sobhit Goswami on Mar 10, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

11/14/2012

pdf

text

original

Sending Keys

You can easily send keys to the active window, as if the user was pressing keys on the keyboard by using the SendKeys statement.
Shell "notepad", vbNormalFocus SendKeys "This is a test string"

The code above runs notepad, and sends the keys 'This is a test string' to it. If you want to use special keys, such as ENTER or TAB, and keys that represent actions rather than characters, use the codes shown below: Key BACKSPACE BREAK CAPS LOCK DEL or DELETE DOWN ARROW END ENTER ESC HELP HOME INS or INSERT LEFT ARROW NUM LOCK PAGE DOWN PAGE UP PRINT SCREEN RIGHT ARROW SCROLL LOCK TAB UP ARROW F1 F2 F3 F4 Code {BACKSPACE}, {BS}, or {BKSP} {BREAK} {CAPSLOCK} {DELETE} or {DEL} {DOWN} {END} {ENTER}or ~ {ESC} {HELP} {HOME} {INSERT} or {INS} {LEFT} {NUMLOCK} {PGDN} {PGUP} {PRTSC} {RIGHT} {SCROLLLOCK} {TAB} {UP} {F1} {F2} {F3} {F4}

to specify to hold down SHIFT while E and C are pressed. CTRL. You must put a space between key and number. To specify to hold down SHIFT while E is pressed. To specify repeating keys. use "+(EC)". followed by C without SHIFT. For example. and ALT keys. {LEFT 42} means press the LEFT ARROW key 42 times. For example. {h 10} means press H 10 times. . CTRL. use the form {key number}. and ALT should be held down while several other keys are pressed. use "+EC". precede the key code with one or more of the following codes: Key Code SHIFT + CTRL ^ ALT % To specify that any combination of SHIFT. enclose the code for those keys in parentheses.F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 {F5} {F6} {F7} {F8} {F9} {F10} {F11} {F12} {F13} {F14} {F15} {F16} To specify keys combined with any combination of the SHIFT.

ByVal dwFlags As Long. ' ' The syntax for specifying keystrokes is the ' same as that of SendKeys . ByVal wMapType As Long) As Long Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte. ' try using a timing loop. Support ' for the following codes has been added. easy. in addition ' to the standard set of codes suppored by SendKeys: ' ' KEY CODE ' break {CANCEL} ' escape {ESCAPE} ' left mouse button {LBUTTON} ' right mouse button {RBUTTON} ' middle mouse button {MBUTTON} ' clear {CLEAR} As Long = &H0 As Long = &H2 .Send keys to any Windows and MS-DOS application Private Declare Function OemKeyScan Lib "user32" (ByVal wOemChar As Integer) As _ Long Private Declare Function CharToOem Lib "user32" Alias "CharToOemA" (ByVal _ lpszSrc As String. but add the ' ability to send keypresses to a DOS application. ByVal lpszDst As String) As Long Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar _ As Byte) As Integer Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _ (ByVal wCode As Long. This module solves that problem and makes sending ' any keys to any Application.Please refer to VB's ' documentation for an in-depth description.VBSendKeys . _ ByVal bScan As Byte. You ' can use SendKeys. ByVal dwExtraInfo As Long) Private Const KEYEVENTF_KEYDOWN Private Const KEYEVENTF_KEYUP Type VKType VKCode As Integer scanCode As Integer Control As Boolean Shift As Boolean Alt As Boolean End Type '--------------------------------------------------------------------' Routine: VbSendKeys() ' ' Author: Bryan Wolf. but you can't send function ' keys. to paste ASCII characters to a DOS ' window from the clipboard. If you need to wait. 1999 ' ' Purpose: Imitate VB's internal SendKeys statement. Note that this does not implement the ' SendKeys's 'wait' argument. ' ' Arguments: Keystrokes. DOS or Windows.

and C keys. B. to keep the SHIFT key pressed while you type ' A.' shift {SHIFT} ' control {CONTROL} ' alt {MENU} or {ALT} ' pause {PAUSE} ' space {SPACE} ' select {SELECT} ' execute {EXECUTE} ' snapshot {SNAPSHOT} ' number pad 0 {NUMPAD0} ' number pad 1 {NUMPAD1} ' number pad 2 {NUMPAD2} ' number pad 3 {NUMPAD3} ' number pad 4 {NUMPAD4} ' number pad 5 {NUMPAD5} ' number pad 6 {NUMPAD6} ' number pad 7 {NUMPAD7} ' number pad 8 {NUMPAD8} ' number pad 9 {NUMPAD9} ' number pad multiply {MULTIPLY} ' number pad add {ADD} ' number pad separator {SEPARATOR} ' number pad subtract {SUBTRACT} ' number pad decimal {DECIMAL} ' number pad divide {DIVIDE} ' ' Sample Calls: ' VbSendKeys "Dir~" ' View a directory of in DOS ' ' NOTE: there is a minor difference with SendKeys syntax. while VB's SendKeys uses regular brackets. you must run the following statement ' VBSendKeys "+{abc}" ' while the syntax of the built-in VB function is ' SendKeys "+(abc)" '--------------------------------------------------------------------Sub VbSendKeys(ByVal sKeystrokes As String) Dim iKeyStrokesLen As Integer Dim lRepetitions As Long Dim bShiftKey As Boolean Dim bControlKey As Boolean Dim bAltKey As Boolean Dim lResult As Long Dim sKey As String Dim iAsciiKey As Integer Dim iVirtualKey As Integer Dim i As Long Dim j As Long Static bInitialized As Boolean Static AsciiKeys(0 To 255) As VKType Static VirtualKeys(0 To 255) As VKType On Error GoTo 0 . You can ' group multiple characters under the same shift key using ' curly brackets. ' For example.

1) sKeystrokes = Mid$(sKeystrokes. 2) Do While InStr(" ^%+".scanCode = OemKeyScan(Asc(OEMChar)) And &HFF Next iKey ' Initialize VirtualKeys() For iKey = LBound(VirtualKeys) To UBound(VirtualKeys) VirtualKeys(iKey). Alt or Shift specifiers sKey = Left$(sKeystrokes.Control = (keyScan And &H200) AsciiKeys(iKey). OEMChar AsciiKeys(iKey).VKCode = iKey VirtualKeys(iKey).If Not bInitialized Then Dim iKey As Integer Dim OEMChar As String Dim keyScan As Integer ' Initialize AsciiKeys() For iKey = LBound(AsciiKeys) To UBound(AsciiKeys) keyScan = VkKeyScan(iKey) AsciiKeys(iKey). 0) ' no use in initializing remaining elements Next iKey bInitialized = True ' don't run this code twice End If ' End of initialization routine ' Parse the string in the same way that SendKeys() would Do While Len(sKeystrokes) lRepetitions = 1 ' Default number of repetitions for each character bShiftKey = False bControlKey = False bAltKey = False ' Pull off Control. sKey) > 1 ' The space in " ^%+" is necessary If sKey = "+" Then bShiftKey = True ElseIf sKey = "^" Then bControlKey = True ElseIf sKey = "%" Then bAltKey = True End If sKey = Left$(sKeystrokes.VKCode = keyScan And &HFF ' low-byte of key ' code AsciiKeys(iKey). "}") If i > 0 Then scan . 2) Loop ' Look for "{}" If sKey = "{" Then ' Look for the "}" i = InStr(sKeystrokes. 1) sKeystrokes = Mid$(sKeystrokes.Alt = (keyScan And &H400) ' Get the ScanCode OEMChar = " " ' 2 Char CharToOem Chr(iKey).Shift = (keyScan And &H100) AsciiKeys(iKey).scanCode = MapVirtualKey(iKey.

1) ' extract the content ' the {} sKeystrokes = Mid$(sKeystrokes.1) End If End If End If End If ' Look for special words Select Case UCase$(sKey) Case "LBUTTON" ' New iVirtualKey = vbKeyLButton Case "RBUTTON" ' New iVirtualKey = vbKeyRButton Case "BREAK".. If i >= 2 Then ' If there is something preceding it. "BKSP" iVirtualKey = vbKeyBack Case "TAB" iVirtualKey = vbKeyTab Case "CLEAR" ' New iVirtualKey = vbKeyClear Case "ENTER". 1) = " " Then ' If a space precedes the ' digits. "~" iVirtualKey = vbKeyReturn Case "SHIFT" ' New iVirtualKey = vbKeyShift Case "CONTROL" ' New iVirtualKey = vbKeyControl Case "MENU". i + 1) ' Remove the } End If ' Look for repetitions i = Len(sKey) Do While Mid$(sKey. "BS"... i. "ALT" ' New iVirtualKey = vbKeyMenu Case "PAUSE" ' New iVirtualKey = vbKeyPause Case "CAPSLOCK" iVirtualKey = vbKeyCapital Case "ESCAPE".. On Error Resume Next ' On overflow. _ 1) <= "9" And i >= 3 i = i .. 1) >= "0" And Mid$(sKey. i. i . If Mid$(sKey. "CANCEL" iVirtualKey = vbKeyCancel Case "MBUTTON" ' New iVirtualKey = vbKeyMButton Case "BACKSPACE"..1 Loop If i < Len(sKey) Then ' If any digits were found. i.between sKey = Left$(sKeystrokes. ignore the value lRepetitions = CLng(Mid$(sKey. i . i + 1)) On Error GoTo 0 sKey = Left$(sKey. "ESC" iVirtualKey = vbKeyEscape Case "SPACE" ' New .

"DEL" iVirtualKey = vbKeyDelete Case "HELP" iVirtualKey = vbKeyHelp Case "NUMLOCK" iVirtualKey = vbKeyNumlock Case "SCROLLLOCK" iVirtualKey = vbKeyScrollLock Case "NUMPAD0" ' New iVirtualKey = vbKeyNumpad0 Case "NUMPAD1" ' New iVirtualKey = vbKeyNumpad1 Case "NUMPAD2" ' New iVirtualKey = vbKeyNumpad2 Case "NUMPAD3" ' New iVirtualKey = vbKeyNumpad3 Case "NUMPAD4" ' New iVirtualKey = vbKeyNumpad4 Case "NUMPAD5" ' New iVirtualKey = vbKeyNumpad5 Case "NUMPAD6" ' New iVirtualKey = vbKeyNumpad6 Case "NUMPAD7" ' New iVirtualKey = vbKeyNumpad7 Case "NUMPAD8" ' New iVirtualKey = vbKeyNumpad8 Case "NUMPAD9" ' New iVirtualKey = vbKeyNumpad9 Case "MULTIPLY" ' New iVirtualKey = vbKeyMultiply .iVirtualKey = vbKeySpace Case "PGUP" iVirtualKey = vbKeyPageUp Case "PGDN" iVirtualKey = vbKeyPageDown Case "END" iVirtualKey = vbKeyEnd Case "HOME" ' New iVirtualKey = vbKeyHome Case "LEFT" iVirtualKey = vbKeyLeft Case "UP" iVirtualKey = vbKeyUp Case "RIGHT" iVirtualKey = vbKeyRight Case "DOWN" iVirtualKey = vbKeyDown Case "SELECT" ' New iVirtualKey = vbKeySelect Case "PRTSC" iVirtualKey = vbKeyPrint Case "EXECUTE" ' New iVirtualKey = vbKeyExecute Case "SNAPSHOT" ' New iVirtualKey = vbKeySnapshot Case "INSERT". "INS" iVirtualKey = vbKeyInsert Case "DELETE".

ALT and SHIFT keys as needed If bShiftKey Then keybd_event VirtualKeys(vbKeyShift). KEYEVENTF_KEYDOWN. 0 End If .VKCode.scanCode.scanCode.Case "ADD" ' New iVirtualKey = vbKeyAdd Case "SEPARATOR" ' New iVirtualKey = vbKeySeparator Case "SUBTRACT" ' New iVirtualKey = vbKeySubtract Case "DECIMAL" ' New iVirtualKey = vbKeyDecimal Case "DIVIDE" ' New iVirtualKey = vbKeyDivide Case "F1" iVirtualKey = vbKeyF1 Case "F2" iVirtualKey = vbKeyF2 Case "F3" iVirtualKey = vbKeyF3 Case "F4" iVirtualKey = vbKeyF4 Case "F5" iVirtualKey = vbKeyF5 Case "F6" iVirtualKey = vbKeyF6 Case "F7" iVirtualKey = vbKeyF7 Case "F8" iVirtualKey = vbKeyF8 Case "F9" iVirtualKey = vbKeyF9 Case "F10" iVirtualKey = vbKeyF10 Case "F11" iVirtualKey = vbKeyF11 Case "F12" iVirtualKey = vbKeyF12 Case "F13" iVirtualKey = vbKeyF13 Case "F14" iVirtualKey = vbKeyF14 Case "F15" iVirtualKey = vbKeyF15 Case "F16" iVirtualKey = vbKeyF16 Case Else ' Not a virtual key iVirtualKey = -1 End Select ' Turn on CONTROL. _ VirtualKeys(vbKeyShift). _ VirtualKeys(vbKeyControl). KEYEVENTF_KEYDOWN.VKCode. 0 End If If bControlKey Then keybd_event VirtualKeys(vbKeyControl).

0 keybd_event AsciiKeys(iAsciiKey).Alt Then keybd_event VirtualKeys(vbKeyMenu). _ AsciiKeys(iAsciiKey). _ VirtualKeys(vbKeyShift).scanCode.Control Then keybd_event VirtualKeys(vbKeyControl).scanCode. _ VirtualKeys(vbKeyControl). _ VirtualKeys(vbKeyMenu).Shift Then keybd_event VirtualKeys(vbKeyShift). 0 ' Turn on CONTROL.scanCode. ALT and SHIFT keys as needed If Not bShiftKey Then If AsciiKeys(iAsciiKey). 0 Else ' ASCII Keys For j = 1 To Len(sKey) iAsciiKey = Asc(Mid$(sKey.scanCode. 0 End If End If If Not bControlKey Then If AsciiKeys(iAsciiKey). _ KEYEVENTF_KEYDOWN. j.VKCode. _ VirtualKeys(iVirtualKey).scanCode. _ VirtualKeys(vbKeyShift). _ KEYEVENTF_KEYUP. _ VirtualKeys(vbKeyMenu). KEYEVENTF_KEYDOWN.If bAltKey Then keybd_event VirtualKeys(vbKeyMenu).VKCode. ALT and SHIFT keys as needed If Not bShiftKey Then If AsciiKeys(iAsciiKey).VKCode. KEYEVENTF_KEYDOWN. 0 End If ' Send the keystrokes For i = 1 To lRepetitions If iVirtualKey > -1 Then ' Virtual key keybd_event VirtualKeys(iVirtualKey). KEYEVENTF_KEYUP.scanCode. 0 End If End If ' Press the key keybd_event AsciiKeys(iAsciiKey). _ KEYEVENTF_KEYDOWN.VKCode.scanCode.VKCode.VKCode.Shift Then keybd_event VirtualKeys(vbKeyShift). _ KEYEVENTF_KEYDOWN. _ AsciiKeys(iAsciiKey). 1)) ' Turn on CONTROL.VKCode. _ VirtualKeys(iVirtualKey). 0 End If End If .scanCode. KEYEVENTF_KEYDOWN.VKCode. 0 End If End If If Not bAltKey Then If AsciiKeys(iAsciiKey). KEYEVENTF_KEYUP. 0 keybd_event VirtualKeys(iVirtualKey).VKCode.scanCode.

If Not bControlKey Then If AsciiKeys(iAsciiKey). _ VirtualKeys(vbKeyMenu).VKCode.VKCode. ALT and SHIFT keys as needed If bShiftKey Then keybd_event VirtualKeys(vbKeyShift). 0 End If End If If Not bAltKey Then If AsciiKeys(iAsciiKey). _ VirtualKeys(vbKeyShift).VKCode. 0 End If If bControlKey Then keybd_event VirtualKeys(vbKeyControl). _ KEYEVENTF_KEYUP.VKCode. 0 End If Loop ' sKeyStrokes End Sub Bryan Wolf .Alt Then keybd_event VirtualKeys(vbKeyMenu). KEYEVENTF_KEYUP. 0 End If End If Next j ' Each ASCII key End If ' ASCII keys Next i ' Repetitions ' Turn off CONTROL. 0 End If If bAltKey Then keybd_event VirtualKeys(vbKeyMenu). _ VirtualKeys(vbKeyControl).scanCode.scanCode. KEYEVENTF_KEYUP.scanCode.scanCode.scanCode.VKCode. KEYEVENTF_KEYUP. _ VirtualKeys(vbKeyMenu).Control Then keybd_event VirtualKeys(vbKeyControl). _ KEYEVENTF_KEYUP. _ VirtualKeys(vbKeyControl).

Notepad") SendKeys.WINFOCUS w = SendKeys. (Alt + fx) Dim w As New SendKeys.Send("Hello".GetWinHandles("New Text Document .GetCommands() If you want to open a file menu. False) If you want to open the system menu of a notepad and Maximize screen. w.GetWinHandles("New Text Document . w.Send("". 1.Show(sent.Send("+(a)".Notepad") SendKeys. SendKeys. (Alt + f) Dim w As New SendKeys. w.ToString & " keys sent") If you want to view available commands._ Notepad". 1).WINFOCUS w = SendKeys.GetWinHandles("New Text Document . (Alt + Space) Dim w As New SendKeys. 1. False) If you want to access sub menu shortcuts. SendKeys.Send("%(fx)". w.WINFOCUS w = SendKeys. False) If you want capitalize a letter. w) MessageBox.Send("%({space}x)". "Edit".GetWinHandles("New Text Document .WINFOCUS w = SendKeys.GetWinHandles("New Text Document .GetWinHandles("New Text Document .Send("%(f)". w. False) If you want to get the number of keys sent. False) If you want print the current document.WINFOCUS w = SendKeys.Notepad") SendKeys.Notepad") SendKeys. SendKeys.Notepad") SendKeys.Notepad".Send("^(p)". (Ctrl + p) Dim w As New SendKeys. (Shift + a) Dim w As New SendKeys.GetWinHandles("New Text Document . "Edit". 1) Dim sent As Int32 = SendKeys. Dim w As New SendKeys.SendKeys If you want set focus without sending keys. False) .WINFOCUS w = SendKeys.

False) Important Note: Different versions of VB. MediaNextTrack Back. Nothing. LineFeed 96 . MediaPreviousTrack Oem1 Oemplus Oemcomma OemMinus LButton. RWin Sleep NumPad0 NumPad1 NumPad2 NumPad3 NumPad4 NumPad5 NumPad6 NumPad7 Command KeyCode 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 Command BrowserFavorites BrowserHome VolumeMute VolumeDown VolumeUp MediaNextTrack MediaPreviousTrack MediaStop MediaPlayPause LaunchMail SelectMedia LaunchApplication1 LaunchApplication2 Back. False) If you want to log off of 2000/XP immediately. (Ctrl+Shift+Escape) SendKeys. Here is a complete list of key commands for 2005 with the 2.Send("^(+({escape}))". XButton2 Back Tab LineFeed Clear Return RButton. False) If you want to open Task manager.NET.Send("^({escape})".NET have different names for certain keys. Return ShiftKey ControlKey Menu KeyCode 85 86 87 88 89 90 91 92 93 94 95 97 98 99 100 101 102 103 U V W X Y Z LWin RWin Apps RButton. Clear RButton. I recommend checking what the key names are for your version of VB. by using the GetCommands sub. (Ctrl + Escape) SendKeys. For example.NET 2003 is now the {return} key on VB.NET 2005.0 framework: KeyCode 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Command None LButton RButton Cancel MButton XButton1 XButton2 LButton.If you want to open start menu. Nothing.Send("#(l)". the {enter} key on VB. Nothing. (Win + L) SendKeys.

Oemtilde FinalMode. Clear. Oemtilde Return. Oemtilde LButton. Oemtilde Back. Oemtilde JunjaMode. Oemtilde RButton. Oemtilde RButton. Oemtilde Tab. Oemtilde ShiftKey. FinalMode. Oemtilde XButton1. Oemtilde LButton. Oemtilde HanjaMode. Oemtilde LineFeed. FinalMode Escape IMEConvert IMENonconvert IMEAceept Space PageUp Next End Home Left Up Right Down Select Print Execute PrintScreen Insert Delete Help 104 105 106 107 108 109 110 111 112 113 114 115 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 NumPad8 NumPad9 Multiply Add Separator Subtract Decimal Divide F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 OemPeriod OemQuestion Oemtilde LButton. LineFeed. XButton2. Oemtilde Cancel. Oemtilde MButton. Oemtilde XButton2. Oemtilde RButton. Return. Oemtilde RButton. Oemtilde ControlKey. Oemtilde Pause. Oemtilde Capital. Oemtilde Clear. Oemtilde RButton.19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 Pause Capital KanaMode RButton. Oemtilde KanaMode. Oemtilde Menu. IMEModeChange 116 . Capital. Capital JunjaMode FinalMode HanjaMode RButton.

F21 Back. D9 64 A B C D E F G H I J 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 F22 F23 F24 Back. OemBackslash Home. NumLock XButton2. Oemtilde Back. Oemtilde Select. OemBackslash D4. OemBackslash Tab. Scroll LineFeed. F23 Back. F24 NumLock Scroll RButton. ProcessKey RButton. F17 Back.Oemtilde 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 RButton. F22 Back. Scroll XButton2. Scroll Clear. NumLock Back. OemBackslash Packet Down. NumLock Clear. 219 220 221 222 223 224 225 226 227 228 229 230 231 233 234 235 236 237 238 239 240 241 242 243 244 245 OemOpenBrackets Oem5 Oem6 Oem7 Oem8 Space. ProcessKey Clear. D8 RButton. Oemtilde ShiftKey. NumLock MButton. Oemtilde ProcessKey MButton. Oemtilde Back. Scroll Back. Scroll MButton. F20 Back. NumLock LineFeed. Oemtilde PageUp. NumLock RButton. OemBackslash PrintScreen. D8 MButton. Clear. F18 Back. Oemtilde D1. Packet D0. NumLock 232 . OemBackslash Back. F19 Back. D9 XButton2. OemBackslash ControlKey. Oemtilde OemBackslash LButton. D9 MButton. D8 XButton2. Scroll RButton. Clear. Oemtilde ShiftKey.

False. "Start". 100) If you want to move the cursor to screen coordinates.ToString) If you want to click a button or other window. The main window and child under the cursor. OemClear Mouse Functions If you want to get the windows that have mouse focus. False) MessageBox. Dim w As New SendKeys. Nothing. "GroupBox3". 1.WINFOCUS w = SendKeys.Move.WINFOCUS = SendKeys.GetWinHandles("Form1".ToString & vbCrLf & w. _ 1. w) If you want to move from current cursor position. True.Scroll 75 76 77 78 79 80 81 82 83 84 K L M N O P Q R S T 160 161 162 163 164 165 166 167 168 169 170 LShiftKey RShiftKey LControlKey RControlKey LMenu RMenu BrowserBack BrowserForward BrowserRefresh BrowserStop BrowserSearch 246 247 248 249 250 251 252 253 254 255 Attn Crsel Exsel EraseEof Play Zoom NoName Pa1 OemClear LButton. False. "GroupBox1".Click(Buttons. False. 1.LeftClick.GetWinFocus(True. Nothing. "GroupBox2". SendKeys.Sleep(3000) Dim w As SendKeys.Click(Buttons. False. 1. SendKeys. _ . SendKeys.Click(Buttons.Show(w. 100. True.MoveAbsolute.Focus.Foreground. 1) SendKeys.

_ "Item21". "Item12". All keys between 0 and 255 can be called! See the GetCommands sub for all available commands. "Item23". Advantages of the SendKeys Module over the SendKeys Class Keyboard focus is maintained on the application by using a keyboard hook and SetForegroundWindow. SendKeys. 1. "Item9".ClickMenu(True. "Edit". When a key being pressed represents an action that starts a new window. It also can use the AttachThreadInput API when the intended focus window is an external application. 1. "Item6". "Form1". Other applications are locked out from using the SetForegroundWindow function while keys are being sent. "Item10". 1. Another dependable method is the new Send method. Win+key combos are now possible (2000/Xp) and are expressed as a string: "#(l)" (Win+L). 1. "".100. 1. 3. GetWinHandles can find and . SendKeys. The SendKeys module is fully commented line by line. by specifying the indexes only and no name. "Form1". "". you can wait until that window exists before sending more keys. 1. 2) If you want to click an item by specifying both captions and indexes. 1. 1. "". SendKeys. such as InputToWin and SendKeysToWindow.WaitForWindow("Print") What's Under the Hood? This module is built upon previous classes. The most reliable methods for sending keys are Text and Message. The foregroundwindow can be returned to its original position. SendKeys. as a command message. 1. _ "Item18". "". 1. When keys are sent from this module. _ "". "Form1".ClickMenu(True. 1. "Item15". "Edit". SendKeys. use the WaitForWindow function. "". 1.Send but were still incomplete. 2) If you want to wait for a window to exist before moving on. external keys entered by the user are ignored by the hook. "Item2". "Form1". _ 1. which were pretty reliable compared to SendKeys. with the WINFOCUS structure. 1. "Item15". You now can send keys directly to a child window by using the GetWinHandles or GetWinFocus(False) methods. 1. and only the keys sent from inside the module are allowed. 1) If you want to click the 23rd menu item. "File".ClickMenu(True. 1) If you want to click the 12th menu item.ClickMenu(True. 2. 1. 100) If you want to click the 12th menu item. 1. to make it easier for others to learn and understand what's going on behind the scenes. it sends messages or uses a keyboard hook to ensure that the foreground window is maintained.

"{hello 10}" repeats the hello string ten times. Complex key combinations are possible. minimized. Strings can be repeated. in other words. The Sleep method provides a unique way to overcome timing issues. Disadvantages of the SendKeys Module Compared to the SendKeys Class None yet known. See the GetCommands sub. or hidden window. Keys can be sent to a disabled. Let me know if you find any! Author name: Shane Findley .verify any window handle. or start an executable path.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->