IAMK Posted April 24, 2018 Posted April 24, 2018 (edited) I have tried all different things (including bad workarounds) I could think of implementing or searching for... I am unable to figure out how to press keyboard buttons in the window I wish to have access. NOTE: I have a GUI which I force to the top at all times (It's an overlay). Here is my very simple code. An image sits at the top and presses 3 keyboard buttons (F2, then 2, then F2) when clicked on: #include <Date.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $K_GUI = GuiCreate("K_GUI_BUTTON", 500, 200, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW) ;Create a window-less GUI. WinSetOnTop($K_GUI, "", 1) ;Keeps the window on the top. WinSetTrans($K_GUI, "", "255") ;Make the window invisible. $pic = GUICtrlCreatePic("image.jpg", 0, 0, 500, 200) GUISetState() While(1) $msg = GUIGetMsg() If $msg = $pic Then ControlSend("[TITLE:Shell]", "", "x", "{F2}{2}{F2}") EndIf Sleep(1000) WEnd I have tested that the image click works with a MsgBox(), but I can't get the keyboard inputs to work. Thank you in advance. Edited April 24, 2018 by IAMK
IAMK Posted April 24, 2018 Author Posted April 24, 2018 Well, I guess I found a working workaround... While(1) $msg = GUIGetMsg() If $msg = $pic Then MouseClick("Primary", 10, 10, 1, 0) Send("{F9}{5}{F9}") EndIf Sleep(1000) WEnd The mouseclick clicks on the window I was trying to control send to. I'm not too happy with this method though. I would still like better solutions to this, if there are any.
Developers Jos Posted April 24, 2018 Developers Posted April 24, 2018 Have you checked the success of the ControlSend() as you are sending it to the ControlID "x" which I guess is your way of saying "any"? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
IAMK Posted April 26, 2018 Author Posted April 26, 2018 On 4/24/2018 at 7:01 PM, Jos said: Have you checked the success of the ControlSend() as you are sending it to the ControlID "x" which I guess is your way of saying "any"? I looked at the help page for ControlSend() and saw "Edit1", which I thought was a random string, hence why I just renamed it to "x" for any, like you said. After reading your comment, I realised that "Edit1" is an actual expected value...
Zedna Posted April 26, 2018 Posted April 26, 2018 (edited) As Jos said try ControlSend("[TITLE:Shell]", "", "", "{F2}{2}{F2}") instead of previous incorrect ControlSend("[TITLE:Shell]", "", "x", "{F2}{2}{F2}") When ControlID is empty then it's sent to "active" control (with focus) Edited April 26, 2018 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
IAMK Posted April 27, 2018 Author Posted April 27, 2018 @Zedna, Yes, I tried it again after re-reading and it worked. Thanks for the response.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now