chitika

Sunday, September 11, 2011

vb: How to how to use sendkeys?

In vb / visual basic, you can use sendkeys function to let program "Press" the keys. Before sending keys to another control, you should make sure that the focus must be set on that control. The following is an example:

Text1.SetFocus

sendkeys "this is a test"

Note:

The above is for the textbox and you can do the same to other controls.

But, to set focus on (Activate) other Program is a different story. You need to use "AppActivate" function. The following is an example:

AppActivate("Untitled - Notepad")

SendKeys "this is a test"

Note:

1. The Above is to Activate (or set focus on) a running Notepad process.

2. "Untitled - Notepad" is the title of Notepad window.

3. To use the above code, you need to open Notepad first.

Instead of using Title, you can also use the window's ID. The following is how to do it:

notepadID = Shell("c:\windows\notepad.exe", AppWinStyle.NormalFocus)
AppActivate(notepadID)

For using combined keys, the following is an example for "Alt+Ctrl+Del":

SendKeys "^%{DELETE}"



--------------------------------------------------------------------------------
The following common key code is for your reference:
--------------------------------------------------------------------------------

Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
SHIFT +
CTRL ^
ALT %
SPACE {space}


Note:

If "sendkeys {space}" is not working, you can try to use "sendkeys {" "}" instead.

No comments:

Post a Comment

For other hundreds of computer repair tips, tricks, tweaks, guide, help, please go to


http://website.edusoftmax.com