Question: Possible to send events to individual window?
Hi,
I have been looking at the AHK package, and was wondering if it was possible to send a event to a specific window, rather than the system in general. I know that there is win.send('keys'), but I need functions like key_down or pixel_search for a individual window.
For example, I need to send 'A' keypress down to Adobe Flash Player (inactive window). Is this possible?
I think you can send special keys and down keys directly to a window using the send method (which uses ControlSend under the hood). For example to send CTRL down:
win.send('{Ctrl down}')
Should be pretty much the same as:
ControlSend,,{Ctrl down}, ahk_id 0x1234 ; where 0x1234 is the window AHK ID.
Let me know if that works for you.
As for pixel_search I think your best bet would be to get the window position and dimensions and pass that to pixel_search which should work with the default Screen coord mode:
x1, y1, width, height = win.rect
x2 = x1 + width
y2 = y1 + height
pixel_color = '0x9d6346'
pixel_search(pixel_color, upper_bound=(x1, y1), lower_bound=(x2, y2))
This should search the screen for the pixel within the boundaries of where the window is located.
Maybe in the future a helper method can be provided so one could simply call win.pixel_search(...) or similar that would have the same effect.
Though, I'm not sure if there's any way to do this if the window is not visible on screen (with or without the library wrapper).
FYI: In the not-too-distant future I'll be publishing a major version update for this library which will also include support for controls, so you should also be able to send keys/clicks/etc directly to specific controls within a window pretty easily, too.