Recently I've been trying to rebind the 3-finger gestures of my Logitech Wireless Trackpad to switch between desktops in Windows 10. The code I used was the following:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
XButton1::SendInput {LCtrl down}{LWin down}{Right}{LCtrl up}{LWin up}
XButton2::SendInput {LCtrl down}{LWin down}{Left}{LCtrl up}{LWin up}
#F::Send {LWin down}{Tab}{LWin up}
However, when I press the buttons on my mouse I use for Browser_forward and Browser_Back, the mouse switches between desktops as well. Can you force AutoHotKey to only use the trackpad for it's gestures? If so, how?
You have two options here!
You can exclude certain windows from activating your hotkey
Make your hotkey only active on certain windows excluding all others
You can do this by using #IfWinActive #If WinActive IfWinActive WinGet, lots of options on Functions and Commands for this...
Since you mentioned desktop, I got curious how one would go about detecting if the desktop was Active, below is the result:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
$XButton1::
If (IsDeskTopActive())
SendInput {LCtrl down}{LWin down}{Right}{LCtrl up}{LWin up}
Else
SendInput {XButton1}
Return
$XButton2::
If (IsDeskTopActive())
SendInput {LCtrl down}{LWin down}{Left}{LCtrl up}{LWin up}
Else
SendInput {XButton2}
return
#F::Send {LWin down}{Tab}{LWin up}
IsDesktopActive() { ; Modified.. orignal by HotKeyIt
MouseGetPos,,,win
WinGetClass, class, ahk_id %win%
If class in Progman,WorkerW
Return True
Return False
}
Related
I am trying to open up a webpage and save it as a complete file. This should be a relatively easy task for autohotkey. For some reason my script is not sending key events to the window. Here's the script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn All, StdOut ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Run, www.google.com
WinWaitActive firefox.exe
sleep, 4000
ControlSend, ahk_class MozillaWindowClass, ^s
What would be a better approach to this problem?
Here is my solution:
Run, www.google.com
WinWaitActive ahk_exe firefox.exe
sleep, 4000
Send ^s
There were two main things that were changed for this to work
Include ahk_exe before the name of the exe in the WinWaitActive conditional
Removed the ControlSend and replaced it with a regular Send, since we are already waiting for the Window to be activated
Hope this helps, feel free to ask for any more clarification or help if you need it
ControlSend, ahk_parent, ^s, ahk_class MozillaWindowClass
I am trying to add a program specific shortcut, i.e. a shortcut to be used inside OneNote App only, and not the short cut for the opening of app itself.
Here is how the present script is:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive, ahk_exe OneNote.exe
+Enter::
Send, {(}!+d{)}
return
But the above one works in OneNote desktop and not for the "OneNote for Windows 10" app (OW10A); how do I make it work for that store app? I am not able to find .exe for the store app to mention it in the above script.
You can use the #If- or the #IfWinActive- directive to create context-sensitive hotkeys and hotstrings:
#If WinActive("WinTitle ahk_class WinClass", "WinText", "ExcludeTitle", "ExcludeWinText")
#IfWinActive, WinTitle ahk_class WinClass, WinText, ExcludeTitle, ExcludeWinText
https://autohotkey.com/docs/commands/_If.htm
Use Window Spy to get detailled information about the program windows.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ; Title can be part of the full title
#If WinActive("- OneNote ahk_class ApplicationFrameWindow", "OneNote")
+Enter:: Send, {(}!+d{)}
; Here you can add more program specific shortcuts:
; ...
; Here you can add specific shortcuts for another program:
#If WinActive("- Microsoft Edge ahk_class ApplicationFrameWindow", "Microsoft Edge")
+Enter:: MsgBox, You pressed Shift+Enter in Microsoft Edge
#If ; turn off context sensitivity
I've got a script running which binds numpad numbers to inline numbers (in order to easily add Unicode chars on the fly because I'm on a laptop without the numpad) and that also binds Home and End to Ctrl+Left and Ctrl+Right respectively. Now, the whole script can be paused by pressing the Apps key, but I'd like the numpad bindings to be the only part toggled and keep Ctrl+Arrows binding always running instead. How can I modify this script to do that?
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
^Left::Send {Home}
+^Left::Send {LShift down}{Home}{LShift up}
^Right::Send {End}
+^Right::Send {LShift down}{End}{LShift up}
0::Numpad0
1::Numpad1
2::Numpad2
3::Numpad3
4::Numpad4
5::Numpad5
6::Numpad6
7::Numpad7
8::Numpad8
9::Numpad9
Appskey::
Suspend,Toggle
return
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
; These hotkeys are always active (even if the script is suspended):
^Left::
Suspend Toggle
Send {Home}
Suspend Toggle
return
+^Left::
Suspend Toggle
Send {LShift down}{Home}{LShift up}
Suspend Toggle
return
^Right::
Suspend Toggle
Send {End}
Suspend Toggle
return
+^Right::
Suspend Toggle
Send {LShift down}{End}{LShift up}
Suspend Toggle
return
Appskey:: Suspend,Toggle
; These hotkeys are inactive if the script is suspended:
0::Numpad0
1::Numpad1
2::Numpad2
3::Numpad3
4::Numpad4
5::Numpad5
6::Numpad6
7::Numpad7
8::Numpad8
9::Numpad9
https://autohotkey.com/docs/commands/Suspend.htm#Remarks:
Any hotkey/hotstring subroutine whose very first line is Suspend
(except Suspend On) will be exempt from suspension. In other words,
the hotkey will remain enabled even while suspension is ON. This
allows suspension to be turned off via such a hotkey.
This is my first AHK script and I'm having trouble getting it to do what I want. Using the key combination Ctrl+Alt+A in Notepad, I want to jump to the beginning of a line of text, select the first character, copy it to the clipboard, and check what letter it is. Right now, I'm just trying to check the contents of the clipboard using a MsgBox but there's a problem: the MsgBox displays it's contents before the copy command! Here's the script:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#IfWinActive, ahk_class Notepad
^!a::
Send, {Home}
Send, {LShift Down}{Right}{LShift Up}
Send, ^c
MsgBox, %clipboard%
return
Running the command multiple times, you will see that it copies the selected text after it displays the MsgBox. It displays the text from the previous command. Any ideas of what I might be doing wrong?
Update: It would seem that the little piece of script that I neglected to include in the question might be the culprit: SendMode Input ; Recommended for new scripts due to its superior speed and reliability. I've updated the script above also. When I remove that line, it works as expected. Can anyone tell me why?
Is it simply that you've not added the return, line to the end of the code?
^!a::
Send, {Home}
Send, {LShift Down}{Right}{LShift Up}
Send, ^c
MsgBox, %clipboard%
return,
alternatively you could add a delay, the command for this is sleep, 1000 = 1 second.
If it fails, try this:
^!a::
Send, {Home}
Send, {LShift Down}{Right}{LShift Up}
Send, ^c
sleep, 200
MsgBox, %clipboard%
return,
The removal of SendMode Input ; Recommended for new scripts due to its superior speed and reliability. rectified the problem.
I know I'm missing something obvious but I can't figure out why this doesn't work. Why doesn't hello show up in the first msgbox I know it says the variable isn't assigned if I uncomment #Warn? This is the only thing in the ahk file.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
ADPass = hello
!5::
MsgBox, %ADPass%
Msgbox, test
return
Your assignment of ADPass never gets executed because it is between 2 hotkeys. You must place it before you begin your hotkeys (before ^!z) or place it within your hotkey (!5) to ensure it is executed.
I think the other answer would probably work, you need the variable to be set before the return. The return means the machine is never getting to that line of code, Try this.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
ADPass = hello; this doesn't have to stay here, just make sure it's before the return.
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
!5::
MsgBox, %ADPass%
Msgbox, test
return
or
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
; Reload the script
^!z::
WinActivate, ahk_class Notepad++
Send {ctrl down}s{ctrl up}
sleep 100
Reload
return
!5::
goto set
point:
MsgBox, %ADPass%
Msgbox, test
return
set:
ADPass = hello
goto point
Return