WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sending Keystrokes

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

SendKey with ALT Character Not Working


Question:

I am trying to troubleshoot a script written by someone else. In the script we are trying to send a username and password to the active dialog box. The target system is XP but this worked flawlessly on our Win2000 PCs.

The script is as follows:

SendKey("!u") ;MOVE TO USERNAME FIELD
TimeDelay(3)
SendKey(username) ;ENTERS %USERNAME%
TimeDelay(3)
SendKey("!p") ;MOVES TO PASSWORD FIELD
TimeDelay(3)
SendKey(password_1);ENTERS %PWD% SPECIFIED ABOVE
TimeDelay(3)
SendKey("{ENTER}") ;SELECT OK BUTTON
What happens is in the currently selected field a 'u' is entered, there is a 3 second delay, then the username is entered, 3 second delay, 'p' is entered, 3 second delay, password is entered, 3 second delay and then "ENTER".

According to the WIL reference manual, the syntax is correct. Any idea on how to fix this?

Answer:

First make absolutely sure that the shortcut keys for the user name & password fields are 'alt-u' and 'alt-p'. You may need to use winver() to figure out which version you're running then use some different code for each.

I also recommend adding code to make sure you are sending the keys to the correct window title. What is the title of this window? Change SendKey to SendKeysTo. You might also want to add a WinWaitExist to help with keystroke timing.


windowtitle = "Please Enter User and Password"
if !WinWaitExist(windowtitle,10)
Message("Error: Window Not Found",windowtitle )
endif

SendKeysto(windowtitle,"!u") ;MOVE TO USERNAME FIELD
SendKeysto(windowtitle, username) ;ENTERS %USERNAME%
SendKeysTo(windowtitle, "!p") ;MOVES TO PASSWORD FIELD
SendKeysTo(windowtitle, password_1);ENTERS %PWD% SPECIFIED ABOVE
SendKeysTo(windowtitle, "{ENTER}") ;SELECT OK BUTTON
Or Maybe do a small TimeDelay before the SendKey("!u")

User Note:

I've had the same problem...Starting somewhere around 2K, MS got the brilliant idea to not have the accelerator keys work by default. So, you may have to turn the accelerator keys back on, using some control panel option (I think it is in Display). You can either do this manually, or you can SysParamInfo() to do it programmically (in WB). Or, you can SendKey {Alt}, then the key, basically simulating exactly what you do when you do it manually. I know for a fact that this works, but it is easier to just turn the accelerators back on.

Sendkey("{ALT}u")
watch those curly braces.

If none of these recommendations help: I recommend you completely ditch the current script, and figure out "RoboScripter". With only a little luck it will write all the code you need to do this operation almost instantly.


Article ID:   W16715
File Created: 2005:02:18:12:21:58
Last Updated: 2005:02:18:12:21:58