Jump to content

Keyboard reset?


SPC
 Share

Recommended Posts

I have an issue with a script losing keyboard state after performing some ControlSend and ControlClick commands to an installer window. It appears that the installer changes the keyboard state such that later commands cannot be sent - as if the ALT key is depressed (even though it was not called). My script calls compiled executables to perform various unattended software installations on a new computer, so the executables are chained together and called in a specific order.

I have tried using an _IsPressed check, sending various other characters (ALT, ESC, ALTUP) with no change to effectively reset the keyboard state to 'normal' (i.e. all keys in original default mode).

Is there a way to reset the keyboard before leaving a script, or gain back appropriate keyboard focus on the window?

Thanks in advance.

Link to comment
Share on other sites

I have an issue with a script losing keyboard state after performing some ControlSend and ControlClick commands to an installer window. It appears that the installer changes the keyboard state such that later commands cannot be sent - as if the ALT key is depressed (even though it was not called). My script calls compiled executables to perform various unattended software installations on a new computer, so the executables are chained together and called in a specific order.

I have tried using an _IsPressed check, sending various other characters (ALT, ESC, ALTUP) with no change to effectively reset the keyboard state to 'normal' (i.e. all keys in original default mode).

Is there a way to reset the keyboard before leaving a script, or gain back appropriate keyboard focus on the window?

Thanks in advance.

There is a problem that can occur with Send which affects the shift and the Alt key, and possibly other keys but I have only tested with shift and Alt. If the shift or Alt key is held down at the start of a Send sequence, and released before the sequence ends then the key will stay operated. This is not considered to be a bug. The way to avoid the problem is to check to see if Alt or shift is pressed and if one is then wait until it's released before the Send sequence.

If this isn't the reason for your then it would be interesting if you could make some minimum code to show the problem.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

There is a problem that can occur with Send which affects the shift and the Alt key, and possibly other keys but I have only tested with shift and Alt. If the shift or Alt key is held down at the start of a Send sequence, and released before the sequence ends then the key will stay operated. This is not considered to be a bug. The way to avoid the problem is to check to see if Alt or shift is pressed and if one is then wait until it's released before the Send sequence.

If this isn't the reason for your then it would be interesting if you could make some minimum code to show the problem.

I am scripting a (somewhat difficult) Microsoft Visual Studio install - windows change focus often (and sometimes disappear altogether), titles are re-used, etc. - but have managed to work my way through the main installation using the following:

Opt("WinWaitDelay", 500)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

Opt("SendKeyDelay", 100)

Opt("SendKeyDownDelay", 25)

TraySetState(2)

Run('\\Server2\CD\VS2005TeamEditionForDevelopers\dvd1\vs\autorun.exe')

WinWait("Visual Studio 2005 Setup", "Install Visual Studi")

If Not WinActive("Visual Studio 2005 Setup", "Install Visual Studi") Then WinActivate("Visual Studio 2005 Setup", "Install Visual Studi")

WinWaitActive("Visual Studio 2005 Setup", "Install Visual Studi")

Sleep(500)

Send("{SPACE}")

Sleep(500)

WinWait("Microsoft Visual Studio 2005", "Loading completed")

If Not WinActive("Microsoft Visual Studio 2005 Setup", "Loading completed") Then WinActivate("Microsoft Visual Studio 2005", "Loading completed")

WinWaitActive("Microsoft Visual Studio 2005", "Loading completed")

Sleep(500)

Send("{SPACE}")

Sleep(500)

; at this point, the window focus was difficult to maintain consistently (and because of options also appearing in a TreeView) I changed to use ControlClick and ControlSend - sleep commands were also added to slow the response to give the windows time to draw/focus/accept input

If Not WinActive("Microsoft Visual Studio 2005 Setup - Start Page") Then WinActivate("Microsoft Visual Studio 2005 Setup - Start Page")

WinWaitActive("Microsoft Visual Studio 2005 Setup - Start Page")

Sleep(500)

ControlClick("Microsoft Visual Studio 2005 Setup - Start Page", "", "[CLASS:Button; INSTANCE:38]")

Sleep(500)

ControlClick("Microsoft Visual Studio 2005 Setup - Start Page", "","[CLASS:Button; INSTANCE:40]")

Sleep(500)

WinWait("Microsoft Visual Studio 2005 Setup - Options Page")

If Not WinActive("Microsoft Visual Studio 2005 Setup - Options Page") Then WinActivate("Microsoft Visual Studio 2005 Setup - Options Page")

WinWaitActive("Microsoft Visual Studio 2005 Setup - Options Page")

Sleep(500)

ControlClick("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:Button; INSTANCE:15]")

Sleep(500)

ControlClick("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:Button; INSTANCE:11]")

Sleep(2000)

WinWait("Microsoft Visual Studio 2005 Setup - Options Page", "Feature description")

If Not WinActive("Microsoft Visual Studio 2005 Setup - Options Page", "Feature description") Then WinActivate("Microsoft Visual Studio 2005 Setup - Options Page", "Feature description")

WinWaitActive("Microsoft Visual Studio 2005 Setup - Options Page", "Feature description")

Sleep(500)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(250)

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{DOWN}")

Sleep(500)

ControlFocus("Microsoft Visual Studio 2005 Setup - Options Page", "", "Tree1")

ControlSend("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:SysTreeView32; INSTANCE:1]", "{SPACE}") ;deselect SQL Express

Sleep(500)

ControlClick("Microsoft Visual Studio 2005 Setup - Options Page", "", "[CLASS:Button; INSTANCE:11]")

Sleep(500)

WinWait("Microsoft Visual Studio 2005 Setup - Finish Page", "Feature description:")

If Not WinActive("Microsoft Visual Studio 2005 Setup - Finish Page", "Feature description:") Then WinActivate("Microsoft Visual Studio 2005 Setup - Finish Page", "Feature description:")

WinWaitActive("Microsoft Visual Studio 2005 Setup - Finish Page", "Feature description:")

Sleep(500)

ControlClick("Microsoft Visual Studio 2005 Setup - Finish Page", "", "[CLASS:Button; INSTANCE:2]")

Sleep(500)

WinWait("Visual Studio 2005 Setup")

If Not WinActive("Visual Studio 2005 Setup") Then WinActivate("Visual Studio 2005 Setup")

WinWaitActive("Visual Studio 2005 Setup")

Send("{ALT}") ; added as an attempt to un-press the ALT key - as well I have tried {ALTUP} with no success

Sleep(500)

ControlClick("Visual Studio 2005 Setup", "", "[CLASS:Button; INSTANCE:2]")

Sleep(500)

Exit

The script will work correctly through all the installation windows, however the ALT key seems still pressed, and when the next script is called to install the next application, the focus is on the toolbar (like File, Edit, View) instead of on the window itself. Trying to send the keystroke ALT does not reset the keyboard state properly.

This will work correctly when running the script standalone, and even when calling the pre-installed app and subsequent application install processes when testing, but fails when running the whole script (which runs through approximately 16 application installation procedures).

Link to comment
Share on other sites

There is a problem that can occur with Send which affects the shift and the Alt key, and possibly other keys but I have only tested with shift and Alt. If the shift or Alt key is held down at the start of a Send sequence, and released before the sequence ends then the key will stay operated. This is not considered to be a bug. The way to avoid the problem is to check to see if Alt or shift is pressed and if one is then wait until it's released before the Send sequence.

If this isn't the reason for your then it would be interesting if you could make some minimum code to show the problem.

You say the way to avoid the problem is to check to see if ALT or SHIFT is pressed and wait until it is released before the Send sequence. What is the best way to do this? I think I can use _IsPressed in a loop, but is this something to add to an Adlib section, or run at a specific point in the script?

The other consideration (like my original thought) is to find a way to reset the keyboard state to some default (i.e. check for and ensure that no keys are pressed), but I'm not sure how to do that. Any help on this is appreciated.

Link to comment
Share on other sites

You say the way to avoid the problem is to check to see if ALT or SHIFT is pressed and wait until it is released before the Send sequence. What is the best way to do this? I think I can use _IsPressed in a loop, but is this something to add to an Adlib section, or run at a specific point in the script?

The other consideration (like my original thought) is to find a way to reset the keyboard state to some default (i.e. check for and ensure that no keys are pressed), but I'm not sure how to do that. Any help on this is appreciated.

Still can't get this to work...

Since I can't get AutoIt can't do this reliably, then I may have to resort to using the unattended installer bundled with Visual Studio (but this was causing issues for me as well). Frustrating application to deal with.

Link to comment
Share on other sites

Still can't get this to work...

Since I can't get AutoIt can't do this reliably, then I may have to resort to using the unattended installer bundled with Visual Studio (but this was causing issues for me as well). Frustrating application to deal with.

All you need to do is wait while the key is pressed, then send whatever.

#include <misc.au3>
.
.
.
$Tin = TimerInit()
while _IsPressed("12") or _IsPressed("10");Alt or Shift is down
  sleep(20)
  If TimerDiff($Tin) > 5000 Then MsgBox(262144,'Hey','Take your coffee mug off the keyboard!')
wend
 send(.....

martin

Martin's code paused the script, which pointed me in the right direction. Turns out in a previous script call I sent an ALTDOWN without the corresponding ALTUP; this didn't become evident until after two more script calls. Without Martin's code (even though it wasn't used as intended) I don't know how long I would have been chasing this.

Thanks again for the help. It seems there is no need for a keyboard reset, just more careful scripting. ;-)

SPC

Edited by SPC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...