Jump to content

key press sequence not working


Recommended Posts

Dears,

Please help me.  I need a script that will navigate through a menu. For that, I use the follow key press sequence. {ALT down}{f down}{f up}{s down}{s up}{ALT up}. On the notepad all works fine but on my application not. For sending key press I use function like Send, ControlSend, _WinAPI_Keybd_Event. When I use actual key press on my application it works, but no in autoit script. Please advise what to do.

forum.au3

Link to comment
Share on other sites

you want people to guess at what you are automating? what good does that do? Depending on what you are automating makes a world of difference how you approach it

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Moderators

@Dream4soul while the response you got was way more harsh for someone new to the forum than it needed to be, there is some validity there. You state that in notepad this is working fine, but in your application it does not - yet you don't tell us the application. Nor do you give any idea what "doesn't work" means. We cannot assist in troubleshooting when you provide so little information. Please let us know what application you're trying to automate, what exactly the steps you're carrying out in your script are intended to accomplish, and what isn't working (is it throwing errors, just not pressing the buttons, etc.?). Please help us help you ;)

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Application that I what to manage it is specific application used in airlines companies from SITA called Leason. Access to this application is limited. This is desktop application with menu and terminal area. In this menu I have File->Open. To open this dialog, I can use keyboard. And it is WORKS from keyboard. But when I use autoit nothing happens. First guess was that script is wrong. I make tests on Notepad, all works fine. I try different commands to sent key pressing, all of them work in Notepad but not in my application. My question is, how it is possible that from keyboard it works but from script it doesn’t work? Script attached.

P.S Menu in this application is accessible. I can reedit with  _GUICtrlMenu_GetMenu, _GUICtrlMenu_GetItemText, _GUICtrlMenu_GetItemSubMenu. I try WinMenuSelectItem but it is not working to. ☹((((((

Link to comment
Share on other sites

Depending on what this app is authored in will determine if or how to proceed. What does the information tool return about the elements you want to automate?

 Information tool can be brought up from the editor under the tools menu and you can click on the things that you want to automate and it will return data about that control. If you can do that please post the controls that you care about and we’ll see what the best options would be 

For instance, modern WPF applications are not automatable by plain auto IT And other methods are necessary

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

ahhhh, terminal emulation. have to see what we can do about that. my best bet is @junkew will have something to say about this, but I could be all wrong. I will check out what I can find.

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

I did find out that it has a command line, and that would be so much easier to deal with if you could do that instead.

Anyway, it looks like your Terminal Emulator is authored in Visual Basic 6 and uses some custom controls (AfxOleControl421) but that control may or may not respond to plain AutoIT script. We may have to go down the IUIAutomation thread to automate that GUI which can be a challenge in it's own. I know with our old VB6 stuff and custom controls that is the only way to do it. FAQ 31 section dealing with IUIAuotomation should get you started.

Oh, can you post your code that you have tried?

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

#include <WinAPISys.au3>
#include <MsgBoxConstants.au3>
#include <GuiMenu.au3>
#include <AutoItConstants.au3>
Opt ("TrayIconDebug", 1)

Example()

Func Example()


    ; Retrieve the handle of the Notepad window using the classname of Notepad.
    
    Local $hWnd = WinGetHandle("9U-34801 - Liaison UTS Terminal Emulator")

    ;Local $hWnd = WinGetHandle("Untitled - Notepad")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.")
        Exit
    EndIf

    ; Display the handle of the Notepad window.
    ;MsgBox($MB_SYSTEMMODAL, "", $hWnd)


WinActivate($hWnd)
SendKeepActive($hWnd)
WinWaitActive($hWnd)

Sleep(500)
; _WinAPI_Keybd_Event(0x12, 0)
;ControlSend ($hWnd, "", "", "{ALTDOWN}")
Send("{ALT down}")
;SendInput("!f")
Sleep(500)

;ControlSend ($hWnd, "", "", "f")
Send("{f down}")
; _WinAPI_Keybd_Event(0x46, 0)
Sleep(500)
Send("{f up}")
; _WinAPI_Keybd_Event(0x46, 2)
Sleep(500)
Send("{s down}")
Sleep(500)
Send("{s up}")
;ControlSend ($hWnd, "", "", "{ALTUP}")
Send("{ALT up}")
Sleep(500)
;_WinAPI_Keybd_Event(0x12, 2)
  

EndFunc   ;==>Example

 

Link to comment
Share on other sites

For that menu, your finder did not find anything, which I find very strange. Could you re-check that?

Also, regarding your script: You can't use no arguments to ControlClick or ControlSend, at least give it a title and the proper control ID else you don't know what you are talking to. It also appears like your regular sends don't work either. You must use the AutoIT Info Tool to get the data and use that data in your calls to ControlSend and such.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Local $hWnd = WinGetHandle("9U-34801 - Liaison UTS Terminal Emulator")

    ;Local $hWnd = WinGetHandle("Untitled - Notepad")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.")
        Exit
    EndIf

    ; Display the handle of the Notepad window.
    MsgBox($MB_SYSTEMMODAL, "", $hWnd)


WinActivate($hWnd)
SendKeepActive($hWnd)
WinWaitActive($hWnd)

Sleep(500)
Opt("WinTitleMatchMode", 4)
;if ControlClick($hWnd, "", "[CLASS:AfxOleControl42; INSTANCE:1]",298,264) then
;if ControlClick($hWnd, "", "9U-34801 - Liaison UTS Terminal Emulator") then
if ControlClick($hWnd, "", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) then
    MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull click.")
Else
    MsgBox($MB_SYSTEMMODAL, "","Debug: Click failed." )
   
EndIf

All 3 controls return "Debug: Click failed." :((((

Link to comment
Share on other sites

Quote

Opt("WinTitleMatchMode", 3)

ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264)

try that. we should also be able to get to that Menu it has as well. Please capture the data for that. If you can't capture it, it is some whacky menu control.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Opt("WinTitleMatchMode", 4)
;if ControlClick($hWnd, "", "[CLASS:AfxOleControl42; INSTANCE:1]",298,264) then
;if ControlClick($hWnd, "", "9U-34801 - Liaison UTS Terminal Emulator") then
;if ControlClick($hWnd, "", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) then
;if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]") then ; Debug: Successfull click
if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",20,20) then ;Debug: Click failed.
    MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull click.")
Else
    MsgBox($MB_SYSTEMMODAL, "","Debug: Click failed." )
   
EndIf

"Debug: Click failed.". But if I remove the coordinate x/y Debug: Successfull click. I comment in the code.

Link to comment
Share on other sites

Local $hWnd = WinGetHandle("9U-34801 - Liaison UTS Terminal Emulator")

    ;Local $hWnd = WinGetHandle("Untitled - Notepad")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.")
        Exit
    EndIf

    ; Display the handle of the Notepad window.
 ;  MsgBox($MB_SYSTEMMODAL, "", $hWnd)


WinActivate($hWnd)
SendKeepActive($hWnd)
WinWaitActive($hWnd)

Sleep(500)
Opt("WinTitleMatchMode", 4)
;if ControlClick($hWnd, "", "[CLASS:AfxOleControl42; INSTANCE:1]",298,264) then
;if ControlClick($hWnd, "", "9U-34801 - Liaison UTS Terminal Emulator") then
;if ControlClick($hWnd, "", "[CLASS:msvb_lib_toolbar; INSTANCE:1]",298,264) then
;if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]","left",1,298,266) then ; Debug: Successfull click
if ControlClick($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "","left",1,138,238) then ; Debug: Successfull click
    MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull click.")
Else
    MsgBox($MB_SYSTEMMODAL, "","Debug: Click failed." ) 
EndIf
if ControlSend($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]","","{ALTDOWN}") then ; Debug: Successfull click
    MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull ALTDOWN.")
Else
    MsgBox($MB_SYSTEMMODAL, "","Debug: ALTDOWN failed." ) 
EndIf
Sleep(500)
if ControlSend ($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]", "f") then 
    MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull f.")
Else
    MsgBox($MB_SYSTEMMODAL, "","Debug: f failed." ) 
EndIf
Sleep(500)
if ControlSend ($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]", "y") then 
    MsgBox($MB_SYSTEMMODAL, "", "Debug: Successfull y.")
Else
    MsgBox($MB_SYSTEMMODAL, "","Debug: y failed." ) 
EndIf
Sleep(500)
ControlSend ($hWnd, "9U-34801 - Liaison UTS Terminal Emulator", "[CLASS:msvb_lib_toolbar; INSTANCE:1]", "{ALTUP}")

All steps return successful code but nothing happen :(( only if I use physical keyboard:((

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...