Support additional options for window Click
AHK ControlClick don't focus after and while script implementing.
But autohotkey.Window.click() focus automatically.
What's the problem? I test at BlueStakcs both
from ahk import AHK, autohotkey
ahk = AHK()
win = ahk.win_get(title="BlueStacks") # BlueStacks
autohotkey.Window.click(win, 748, 486)
The implementation of Window.click does use AutoHotkey's ControlClick, as seen here.
My guess is that this is an AHK and application-specific issue, as certain applications may react differently to ControlClick (and not necessarily consistently). For example, web browsers like Chrome seem to have inconsistent behavior with ControlClick.
Hence, I don't think this is an issue with the Python wrapper.
The implementation of
Window.clickdoes use AutoHotkey'sControlClick, as seen here.My guess is that this is an AHK and application-specific issue, as certain applications may react differently to
ControlClick(and not necessarily consistently). For example, web browsers like Chrome seem to have inconsistent behavior with ControlClick.Hence, I don't think this is an issue with the Python wrapper.
Thanks for reply, but at AHK script Controlclick don't focus at all. I test with same bluestacks instance and same time.
What I did with AHK script is like below
ControlClick, x441 y425, ahk_class %sub_class%,, left, D, NA
sleep, 300
ControlClick, x441 y425, ahk_class %sub_class%,, left, U, NA
AHK script and python ahk works properly( clicking works ) but different between them is whether focusing after Controlclick done.
Why I open issue is AHK script is same, so implementing AHK script Python algorithm is problem?
Hmm. It's hard for me to imagine how there's much difference, since this library simply calls ControlClick through AHK.
Try this:
import logging
logging.basicConfig(level=logging.DEBUG)
from ahk import AHK
ahk = AHK()
win = ahk.win_get(title="BlueStacks") # BlueStacks
autohotkey.Window.click(win, 748, 486)
That way, you can see the AHK code that is being executed and post it here. Maybe there's a bug with how the code is being generated.
You could also do something like
my_script = """
; add in other parts of your regular AHK script here
ControlClick, x441 y425, ahk_class %sub_class%,, left, D, NA
sleep, 300
ControlClick, x441 y425, ahk_class %sub_class%,, left, U, NA
"""
ahk.run_script(my_script)
And see if that changes anything.
If you could post the full contents of your script, maybe that could help too.
Log with before code( The focus is still switched. )
Code
import logging
from ahk import AHK, autohotkey
logging.basicConfig(level=logging.DEBUG)
ahk = AHK()
win = ahk.win_get(title="BlueStacks") # BlueStacks
autohotkey.Window.click(win, 882, 571)
Log
DEBUG:ahk.script:Running script text: #NoEnv
#Persistent
WinGet, output, ID, BlueStacks, , ,
FileAppend, %output%, *
ExitApp
DEBUG:ahk.script:Stdout: b'0x404fa'
DEBUG:ahk.script:Stderr: b''
DEBUG:ahk.script:Running script text: #NoEnv
#Persistent
ControlClick, x882 y571, ahk_id 0x404fa
ExitApp
Log with other code( The focus is not changed )
Code
import logging
from ahk import AHK, autohotkey
logging.basicConfig(level=logging.DEBUG)
ahk = AHK()
my_script = """
sub_class := "HwndWrapper[BlueStacks.exe;;e7b2cfc3-e200-4304-9565-26b06dca0d78]"
ControlClick, x882 y571, ahk_class %sub_class%,, left, D, NA
sleep, 300
ControlClick, x882 y571, ahk_class %sub_class%,, left, U, NA
"""
ahk.run_script(my_script)
Log
DEBUG:ahk.script:Running script text:
sub_class := "HwndWrapper[BlueStacks.exe;;e7b2cfc3-e200-4304-9565-26b06dca0d78]"
ControlClick, x882 y571, ahk_class %sub_class%,, left, D, NA
sleep, 300
ControlClick, x882 y571, ahk_class %sub_class%,, left, U, NA
DEBUG:ahk.script:Stdout: b''
DEBUG:ahk.script:Stderr: b''
Is there any improvement?
Interesting. I see that in your script, you are adding some options like , left, U, NA. That could be making the difference here.
I also noticed you're using ahk_class rather than ahk_id I don't think that makes any difference, though.
I think what I'd like to do at this point is make a change to have Window.click support passing these additional options.
options keyword is now supported for control_click (and Window.click) in v1.