How do I automate mouse clicks on a Windows system tray icon using Perl?
I am writing some开发者_运维问答 automation scripts using Perl for testing a custom Windows application. The only way to exit the application is to automate a right click on a system tray icon (which the application creates) and clicking on exit on the menu that it shows. Is it possible to automate such clicks using Perl? I checked the Win32::GuiTest module but could not find much stuff on automating mouse clicks on system tray icons.
I don't know of a robust way to do what you are asking.
But it looks like you can make it work by first calling MouseMoveAbsPix to move to the right location, then SendMouse a RightClick. If you know the exact machine that you will be using, and know where the tray should be, you can click on the tray icon.
But be aware that this will be very, very dependent on what exactly is on the window. And this logic won't work at all if the screen is an any way different than you expect. (For instance there is an unexpected popup.)
Incidentally you might try seeing whether sending the application the key combination ALT+F4 will exit the application. There is a chance that this will work, and it should be much more reliable.
That distribution comes with examples. You first want to play around with spy.pl in order to find out the window name of the appropriate tray icon. Then in your real program you use that name to immediately address the icon, this is position independent.
精彩评论