ControlClick is not working - autohotkey

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.

Related

Keybindings with mouse click

I am developing in C#, and when I hold down cmd (macOS) and Click a method, I am taken to it's Definition. I am looking for a way to be able to hold down cmd+shift and click the method, and be taken to the methods Implementation. I have searched and tested for some time without finding anything; I am starting to think it is not possible.
Does anyone know how, or if it even is possible?
It's currently impossible. Mouse clicks are not considered modifiers and cannot be customized right now. There's an open issue for this: https://github.com/microsoft/vscode/issues/3130.
You can still press command+F12 to jump to Implementation (which may be unhandy, since you have to press Fn as well). Besides, some applications or specific mouses allow you to map keys.

How to make AutoHotkey script for selecting a pen in OneNote(UWP)?

To give you an intro, I am not a programmer but a biologist who is learning a bit of programming.
Now I use OneNote a lot and continuously switch between typing and touch-based inking.
Now OneNote UWP does not have a shortcut for selecting a pen.
But I found out that by pressing Alt+d and then down and then continuously pressing right six times and then pressing enter, one can switch to pen via keyboard.
Now I want to automate the above process and link it to Numpad 1.
So I tried AutoHotkey and tried to learn making a script of the above command but still no success.
This is what I tried (3-4 different ways):
Numpad1::
!d
Down
Right
Right
Right
Right
Right
Right
Right
Enter
I know this script is wrong but I can't find the correct way to do it.
You're off to a good start! In order to send the keystrokes, you'll need to use one of the variations of the Send command. In addition, we can also make it so that it only work when OneNote is the active window using the #If directive. (It makes hotkeys context-sensitive.)
I don't have OneNote on my machine, but please verify that the title contains "OneNote" for the following script to work.
SetTitleMatchMode , 2
#If WinActive("OneNote")
Numpad1::Send , !d{down}{right 6}{enter}
#If
Edit: I installed OneNote to try it out. It appears to run too quickly. I added a key delay of 75ms and changed Send to SendEvent, which obeys the key delay. This worked fine for me:
SetTitleMatchMode , 2
SetKeyDelay , 75
#If WinActive("OneNote")
Numpad1::SendEvent , !d{down}{right 6}{enter}
#If

AutoHotKey Right Click

I don't understand why most of the suggestions aren't working for me, so I'm asking here.
I'm trying to get AHK to right click when I press a shortcut. I found a couple of ways to do it:
^R:: RButton
return
and
^R:: AppsKey
return
and
^R:: Click Right
return
as well as a few others.
However, none of these actually seem to right click as if I were physically right clicking with my mouse. They all seem to right click as though ^R was remapped to Shift+F10, or some other system right click. What I actually want is a real right click, emulated just as if I were right clicking with my mouse. It should work in folders, applications, everywhere. Is there a way to do this?
As #Jim U said in the question's comments, put it in a new script file. From your reply to his comment it seems that solved the problem, so I have written this answer to clarify that.
In programming generally, always isolate the code first as the problem can be caused by something elsewhere.

AutoHotkey #IfWinNotActive not activating

I like having my middle mouse button be a double click, so I have an .ahk script to make that happen, but a lot of programs I use (particular ones involving a 3D environment like Autodesk stuff) need the middle mouse button to function normally, so I have this script:
#SetTitleMatchMode, 2
#IfWinNotActive, Autodesk
MButton::send, {LButton}{LButton}
All this does is make the double click work constantly. As if it's ignoring the WinNotActive completly. I have no idea why this doesn't work. I've tried a few things to see if I could fix it myself, but I made no progress.
Please remember that kind and respectful responces are greatly appreciated.
Context-sensitive directives apply to all following hotstrings and hotkeys. Thus, you have to "reset" this behaviour and limit the scope with another #ifWinNotActive:
#SetTitleMatchMode, 2
#IfWinNotActive, Autodesk
MButton::send, {LButton}{LButton}
#IfWinNotActive
(see https://autohotkey.com/docs/commands/_IfWinActive.htm#Basic_Operation for details)

Autohotkey fails to recognize image under resolution change

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