Autohotkey fails to recognize image under resolution change - autohotkey

I have created an autohotkey scripts which automates a manual process by launching an application and clicking on the script mentioned icons. The script is working fine on one computer which having higher resoultion but fails to execute on other computer with different resoultion. Do you have any suggestions to workout in other way. This app doesn't have any keyboard shortcuts and only executes on mouse clicks. I hope there will be an anwer.

Most Apps Have Alt Shortcuts, have you tried them? also you may try re-adjusting mouse click x,y as per resoulution

::: Explaining the problem ::: Please read to understand the problem.
Lets start off simple you create the autohotkey script on COMPUTER_A, you print_screen/capture all your images & resize them on COMPUTER_A, however when you transfer your files to COMPUTER_B image_search does not find matchs as well or at all, why is this ?
Well COMPUTER_A and COMPUTER_B are two totally different computers, the problem comes cause with two different computers each have different COLOR TEMPLATES installed on them, if you copy the color template from COMPUTER_A onto COMPUTER_B or any computer. Overall problem is different color templates does not allow image_search to find a match pixel by pixel cause the varying difference between the two different computers. Thats why its best to copy color template from computer_A to another computer to allow image search to work properly.
::: Finding the COLOR Template :::
On Win7 --> Control Panel --> Color Management --> Mine was easy to find cause it is the color template that came with my computer monitor, however yours might take a little more work in finding. ICC profiles are generally printers, ICM profiles are display drivers/color templates for you computer screen. Once you find your display profile currently in use on COMPUTER_A find it on your computer storage & copy it to your autohotkey direction for easy access in the future so it can be copied with your autohotkey script to computer_B or computer_Z later. Right Click on the ICM once copied to computer_B and click install & its possible you may need to restart the computer for all changes to take affect.
::: Results :::
Once the color template from computer_A is installed on another computer image_search should work exactly how it does on computer_A, i've personally tested the results on 6 different computers from XP, Vista & Win7, always had a 100% success rate which i believe makes this a universal solution/fix to the image_search problem with other computers.
I do caution those few people who have trouble with this to have patience & do you fair share of research into "windows color profiles" to make this solution work for you, i just foresee someone accidently finding/copying the wrong ICM/ICC profile. Also to be warned if someone installs photography software/development software like adobe photoshop/multimedia/development software sometimes they come with their own ICM/ICC profiles and could overright the existing ones causing image_search to again become a problem. Just reinstall the default ICC/ICM profile again to fix that problem.
::: CONCLUSION :::
I hope this was helpful to someone, sorry for all the writing but i thought it best to share my complete findings with you all since it can get complicated.

Here is how I once solved it.. In the beginning I ask the user to capture the mouse position of each icon, and store these coordinates for later use.
Hotkey, LButton, off ; Make sure that the Left Mouse button inactivator is turned Off
Lbutton:: ; Disable the Left Mouse Button
SplashImage , %A_ScriptDir%/Images/YourScreenShot.jpg,,, Screen shot, Icons ; Show Screenshot of what the user needs to do
SoundBeep 1000, 300 ; wake up user
SplashTextOn, 200, 100, Script Preparations, Please Click on Icon1. ; Show new instructions to the user
WinMove, Script Preparations,, (A_ScreenWidth/2)-150, (A_ScreenHeight/2)-200 ; Move the text instructions window with the name "Script Preparations" 150 pixels right of the center of the screen and 200 pixels up
SoundBeep 600, 300 ; Wake up user
; Here the left mouse button will temporarily be disabled (to prevent actions)
Hotkey, LButton, on ; Turn Left Mouse Button OFF, to capture the Mouse click
KeyWait, LButton, D ; Wait for LeftMouseButton click Down
MouseGetPos, xpos1 ,ypos1 ; Store the position where the mouse was clicked (Icon1)
Repeat this for all icons used.
Then if you want to click on icon1 use:
MouseClick, left, %xpos1% ,%ypos1% ; Perform the mouse click on the captured mouse location

Related

A program runs in Windows' Run, but not with AHK's Run

I'm trying to run Juniper Network's Junos Pulse using AHK. It works when I use Windows' Run App, but not in my AHK script. There is no error - nothing happens:
#j::
Run, C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\Pulse.exe
Return
Things I have tried:
Run, Pulse.exe, %Path%
Run, '%Path%Pulse.exe'
Run, "%Path%Pulse.exe"
Run %Path%Pulse.exe
Also, when I add a MsgBox to open within the command, it opens fine - no issue, but Pulse doesn't open, and no error occurs.
UPDATE: Since the previous line didn't work with Pulse and your answer demands specific screen coordinates and position in taskbar, I made this workaround that may work on every PC regardles of it's resolution/taskbar:
#j::
Send #r
Sleep, 1
clipboard:="C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\Pulse.exe"
Send ^v
Sleep, 1
ControlClick, OK, Run
return
Alternatively, if you want to preserve the 'Clipboard' and use 'Enter' instead of 'ControlClick':
#j::
Send #r
Sleep, 1
Send C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\Pulse.exe
Sleep, 1
Send {Enter}
return
ps: increase the 'Sleep' time to get safer results on slow computers.
Try to run the script as administrator (context menu),
or add this to the auto-execute section (top of the script, before the first return or hotkey):
if not A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%"
ExitApp
}
TL;DR:
Pulse's GUI Implementation disregards standard AHK input. You need to use more indirect input to interact with Pulse. Try this script, changing the click coords to match your own screen:
#CommentFlag ;//
;// Run Junos Pulse
#j::
Send, {LWinDown}4{LWinUp} ;// If Pulse is pinned to your taskbar in the 4th position
Sleep 100
Click 568,315 ;// the position of the Connect button on my screen
Sleep 7000
Click 641,32 ;// the position of the Minimize button
Return
Details
Custom GUI Implementations
Some Apps use a custom GUI implementation. This is typically because they want more control over what the OS can access and how it can access it.
A good example is Google's Chrome, which acts like this in Windows. They probably don't want to share your data with Windows, because it's worth more to them that way.
Junos Pulse is also a special GUI implementation for one to a few of the following reasons: 1) They want to work across as many platforms as possible. 2) They want to add security by limiting the number of ways Windows can access it. 3) It's a poorly written application. 4) It was written for Windows 8, and never actually updated for Windows 10.
Because they use custom implementations instead of the standard MS implementations, they knowingly or accidentally disallow seemingly innocuous functions.
Because Chrome works semi-well with AHK, it's probably less restrictive on how it can be accessed as an application, and more restrictive on how Windows can access the data it stores. This is also part of the reason it's damn near impossible to completely remove your Chrome data from a computer.
Junos Pulse, on the other hand, probably lumps AHK in with intrusive or unsafe malware.
But, there is Hope
Pulse still responds to indirect interactivity such as the mouse and keyboard. So that is what you have to use.
Remember:
You can open programs by adding them to the taskbar and pressing win + number - corresponding to the order of apps pinned to the task bar.
Junos Pulse is the 4th Program on my taskbar:
So I can use win+4 to open it. I send that and some mouse clicks to automate signing in, then minimize the window. Keep in mind, this is specific to my screen (MS Surface Pro), and the placement of the Pulse window when it opens):
#CommentFlag ;//
;// Run Junos Pulse
#j::
Send, {LWinDown}4{LWinUp}
Sleep 100
Click 568,315 ;// the position of the Connect button on my screen
Sleep 7000
Click 641,32 ;// the position of the Minimize button
Return
Use WindowSpy (a tool in SciTE4AutoHotkey) to get the exact mouse coordinates for the Click commands.

ControlClick is not working

My script is supposed to press a button somewhere in my window, upper left. It is not working as it should be. I tried this:
ControlClick ClassNN ThunderRT6UserControlDC29, ahk_class ThunderRT6FormDC
Yet it doesn't work.
I tried the manual option:
Controlclick x160 y60, ....
But that doesn't work as well.
Eventually I resorted to a mere:
Click 160, 60 and that does work.
I was wondering why it is behaving like that? Also, is there a way for merely the button to get pressed without the mouse actually going all the way over there. I looks stupid and it is slow.
The main reason for me asking this question is because it is closely related to another question I posed:
How to obtain textual contents from a window
The common denominator is that anything with classNN and ahk_class seems to be problematic.
Try running script as a administrator (if you're on Windows 7 or Vista)
I finally found my own solution after skimming the documentation more thoroughly:
https://autohotkey.com/docs/commands/ControlClick.htm#Reliability
You can specify NA as the sixth parameter to wait for the mouse button to lift.
I found that when firing Control, Check, ,Button1 prior to ControlClick the click didn't work, but adding the NA to the end somehow magically fixed it. I suppose a click was being simulated and had not yet lifted.
First, make sure you have the capitalization correct. controlclick is case and space sensitive - everything in the name has to be correct.
Second, for your mouse-moving issue - first save the position of your mouse, then controlclick, and then put your mouse back where you found it. The mouse will only be out of place for the duration of either the click or the timeout. 160ms is not noticeable.
You might also try using ahk to activate the window, bringing it the front, and then seeing if you can tab through the controls to the one you want, and then push it by sending keys like space or return to the window in the forefront (which you have activated). This avoids using controlclick altogether. Some windows can be tricky.
Controlclick x160 y60,A,,Left,1, NA
Manual option like that should work,at least in my case it worked.
Left = your mouse button pressed
1 = number of clicks
A = Active Window
Also options to retrieve contents from the games or retrieve variables from other autohotkey parts for ControlClicks or SendMessage/PostMessage seem to not work yet.

How to make an exe for my united iphone application

I created a game using unity iphone.there are six characters in my game,first you click one character,the character was selected, and then you click a target position,the selected character will move to your target position. this function work well in the unity3d iphone engine. however when i build an exe file for it, although the exe file can be opened in window xp, I can only selected the character,the rest operation can't work.I don't know what cause this problem, can you give me some advise.
My build step is below:
In Unity…
Select “File” from the top menu.
Select “Build Settings”
Select “PC & Mac Standalone” under the platforms column (lower left)
On the combo box labelled “Target Platform” select “Windows”
Click “Switch Platform” button (lower left, 1st button).
When all the assets have been reconverted to suit the new platform, you’ll be ready to click the build button (lower right).
Thanks in advance.
You'd need to be more clear on your problem.
First of, did you added Input controls for Mouse control? If not, go to Input settings and add it. There you can basically define which input events (mouse, keyboard, joystick, touchscreen) are mapped to what actions.
For example, if you want mouse and keyboard movement, you have to add Horizontal and Vertical axis twice. Once for mouse input, one for keyboard input. I guess it's same for iPhone, since it's touchscreen you probably have to add some kind of axis or code which will handle it correctly. Can't tell much more, as I don't have iPhone neither the unity license for it.
Second off, your question would be more appropiate to be asked at http://answers.unity3d.com/, which is unity's official Stockexchange version for asking/answering questions and there are only unity developers there.

Does anybody know how to program the Luxeed LED keyboards directly?

I have a Luxeed, either the U5 or the RaMa series (not sure which, these people don't give you a lot to go on). I want to program the LEDs directly, but I have no idea how. Their software isn't that intuitive and seems limited anyway (though it's hard to tell, it being so unintuitive and all). Ideally it would be in Python (or possibly .net, since it should be a Windows service). Anybody have any idea how I would do this? Or where any specs are? Thanks.
From here http://luxeed.com/files/8012/8538/3827/comparison_chart_en.jpg, it seems that if you have a U5 you are in bad luck as it does not seem to be able to interact with the host computer. If you have a rama or U7 maybe the best way to start is by looking to other implementations available in other O.S. .e.g.: kurtstephens.com/luxeed
I've just bought a luxceed U7 (says model on the underside of the keyboard).
The Function Keys (F1-F8) represents each of the colors:
F1(R) == Red
F2(Y) == Yellow
F3(G) == Green
..
To set the colors:
Press [Luxceed] Button
Press a function key, eg F3 for green.
The colored LED to the very right of the keyboard should go green.
Every key on the keyboard you now press will turn Green (unless its already coloured)
Pick a new color, eg F1 for red, what you press will now turn Red
Press [Luxceed] button again to turn off color setting mode (LED to right should go off).
How to save a pattern/design/color layout:
Make a design as above by setting the colors.
Your keyboard can save a few different 'presets', my U7 stores four; P1, P2, P3, P4.
Hold down the [luxceed] key + P1 will save your current design over preset 'P1'.
Press say 'P2' to move off of your preset and over to preset 'P2'. Then press P1 to go back.
Do the presets stay saved? YES
For my U7, I was able to unplug the keyboard (kept it unplugged for a minute) then plugged it back in and it retained the presets I had in memory. I read somewhere that the keyboards did not save the presets when unplugged, but so far the save worked for me.

What determines the monitor my app runs on?

I am using Windows, and I have two monitors.
Some applications will always start on my primary monitor, no matter where they were when I closed them.
Others will always start on the secondary monitor, no matter where they were when I closed them.
Is there a registry setting buried somewhere, which I can manipulate to control which monitor applications launch into by default?
#rp: I have Ultramon, and I agree that it is indispensable, to the point that Microsoft should buy it and incorporate it into their OS. But as you said, it doesn't let you control the default monitor a program launches into.
Here's what I've found. If you want an app to open on your secondary monitor by default do the following:
1. Open the application.
2. Re-size the window so that it is not maximized or minimized.
3. Move the window to the monitor you want it to open on by default.
4. Close the application. Do not re-size prior to closing.
5. Open the application.
It should open on the monitor you just moved it to and closed it on.
6. Maximize the window.
The application will now open on this monitor by default. If you want to change it to another monitor, just follow steps 1-6 again.
Correctly written Windows apps that want to save their location from run to run will save the results of GetWindowPlacement() before shutting down, then use SetWindowPlacement() on startup to restore their position.
Frequently, apps will store the results of GetWindowPlacement() in the registry as a REG_BINARY for easy use.
The WINDOWPLACEMENTroute has many advantages over other methods:
Handles the case where the screen resolution changed since the last run: SetWindowPlacement() will automatically ensure that the window is not entirely offscreen
Saves the state (minimized/maximized) but also saves the restored (normal) size and position
Handles desktop metrics correctly, compensating for the taskbar position, etc. (i.e. uses "workspace coordinates" instead of "screen coordinates" -- techniques that rely on saving screen coordinates may suffer from the "walking windows" problem where a window will always appear a little lower each time if the user has a toolbar at the top of the screen).
Finally, programs that handle window restoration properly will take into account the nCmdShow parameter passed in from the shell. This parameter is set in the shortcut that launches the application (Normal, Minimized, Maximize):
if(nCmdShow != SW_SHOWNORMAL)
placement.showCmd = nCmdShow; //allow shortcut to override
For non-Win32 applications, it's important to be sure that the method you're using to save/restore window position eventually uses the same underlying call, otherwise (like Java Swing's setBounds()/getBounds() problem) you'll end up writing a lot of extra code to re-implement functionality that's already there in the WINDOWPLACEMENT functions.
It's not exactly the answer to this question but I dealt with this problem with the Shift + Win + [left,right] arrow keys shortcut. You can move the currently active window to another monitor with it.
Get UltraMon. Quickly.
http://realtimesoft.com/ultramon/
It doesn't let you specify what monitor an app starts on, but it lets you move an app to the another monitor, and keep its aspect ratio intact, with one mouse click. It is a very handy utility.
Most programs will start where you last left them. So if you have two monitors at work, but only one at home, it's possible to start you laptop at home and not see the apps running on the other monitor (which now isn't there). UltrMon also lets you move those orphan apps back to the main screen quickly and easily.
I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll remember where it was last at and will reopen there, but -- as you've noticed -- it isn't a default behavior.
EDIT: The way I usually do it is to have the location stored in the app's settings. On load, if there is no value for them, it defaults to the center of the screen. On closing of the form, it records its position. That way, whenever it opens, it's where it was last. I don't know of a simple way to tell it to launch onto the second monitor the first time automatically, however.
-- Kevin Fairchild
Important note: If you remember the position of your application and shutdown and then start up again at that position, keep in mind that the user's monitor configuration may have changed while your application was closed.
Laptop users, for example, frequently change their display configuration. When docked there may be a 2nd monitor that disappears when undocked. If the user closes an application that was running on the 2nd monitor and the re-opens the application when the monitor is disconnected, restoring the window to the previous coordinates will leave it completely off-screen.
To figure out how big the display really is, check out GetSystemMetrics.
So I had this issue with Adobe Reader 9.0. Somehow the program forgot to open on my right monitor and was consistently opening on my left monitor. Most programs allow you to drag it over, maximize the screen, and then close it out and it will remember. Well, with Adobe, I had to drag it over and then close it before maximizing it, in order for Windows to remember which screen to open it in next time. Once you set it to the correct monitor, then you can maximize it. I think this is stupid, since almost all windows programs remember it automatically without try to rig a way for XP to remember.
So I agree there are some apps that you can configured to open on one screen by maximizing or right clicking and moving/sizing screen, then close and reopen. However, there are others that will only open on the main screen.
What I've done to resolve: set the monitor you prefer stubborn apps to open on, as monitor 1 and the your other monitor as 2, then change your monitor 2 to be the primary - so your desktop settings and start bar remain. Hope this helps.
Do not hold me to this but I am pretty sure it depends on the application it self. I know many always open on the main monitor, some will reopen to the same monitor they were previously run in, and some you can set. I know for example I have shortcuts to open command windows to particular directories, and each has an option in their properties to the location to open the window in. While Outlook just remembers and opens in the last screen it was open in. Then other apps open in what ever window the current focus is in.
So I am not sure there is a way to tell every program where to open. Hope that helps some.
I've noticed that if I put a shortcut on my desktop on one screen the launched application may appear on that screen (if that app doesn't reposition itself).
This also applies to running things from Windows Explorer - if Explorer is on one screen the launched application will pick that monitor to use.
Again - I think this is when the launching application specifies the default (windows managed) position. Most applications seem to override this default behavior in some way.
A simple window created like so will do this:
hWnd = CreateWindow(windowClass, windowTitle, WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
Right click the shortcut and select properties.
Make sure you are on the "Shortcut" Tab.
Select the RUN drop down box and change it to Maximized.
This may assist in launching the program in full screen on the primary monitor.