Inactivate right click when using it as shortkey - autohotkey

I have successfully made it so that when I hold down the right mouse button I can control the system volume with The scroll wheel. But my problem now is that every time that I release the right button it still right clicks even if I have changed the volume.
I want to retain the normal right click, but not when I have used the right mouse button in a macro (then it should ignore the release of the right mouse button). How do I best add a script to ignore mouse clicks in this situation?
This is what I use at the moment:
~RButton & WheelUp::Send {Volume_Up}
And I like it for its brevity (also, other ways have shown to be buggy), so I hope that there is a simple solution that I have missed.
I think it should be possible to have a timer based solution that works (like for double right click as shortkeys), but I have been unable to use that solution.
Here are solutions I have found that Don't quite solve it:
RButton & WheelUp::Send {Volume_Up} ; inactivates right click
RButton:: click right ; gets right click back, but unable to have right click pressed
;(dragging things with right click, etc would be impossible)
RButton & WheelUp:: Send {Volume_Up}
RButton & WheelDown::Send {Volume_Down}

OK, here is a better solution, I think.
~RButton & WheelUp::
Send {Volume_Up}
SetTimer, CloseContextMenu, 50
return
~RButton & WheelDown::
Send {Volume_Down}
SetTimer, CloseContextMenu, 50
return
CloseContextMenu:
KeyWait, RButton, R
WinGetTitle, active_title, A
WinGetClass, active_class, A
WinActivate, ahk_class Progman ;desktop
WinWaitActive, ahk_class Progman
Send, {ALT Down}{ALT Up} ; try also: Send, {Esc} (remove the Alt command)
SetTimer, CloseContextMenu, off
WinActivate, %active_title% ahk_class %active_class%
return

~RButton & WheelUp::
Send {Volume_Up}
SetTimer, CloseContextMenu, 50
return
~RButton & WheelDown::
Send {Volume_Down}
SetTimer, CloseContextMenu, 50
return
CloseContextMenu:
KeyWait, RButton, R
Send, {Esc}
SetTimer, CloseContextMenu, off
return

Try also this:
#NoEnv
SendMode Input
#SingleInstance Force
Process, Priority, ,High
#InstallKeybdHook
#InstallMouseHook
#UseHook
#MenuMaskKey vk07 ; is used to mask Win or Alt keyup events
; http://ahkscript.org/docs/commands/_MenuMaskKey.htm
return
~RButton & WheelUp::
Send {Volume_Up}
SetTimer, CloseContextMenu, 50
return
~RButton & WheelDown::
Send {Volume_Down}
SetTimer, CloseContextMenu, 50
return
CloseContextMenu:
KeyWait, RButton, R
Send, {ALT Down}{ALT Up}
SetTimer, CloseContextMenu, off
return

Related

Apply hotkeys only while AltTab-ing in AutoHotkey

I want to swap AltTab hotkey in Windows 11 for the hotkey Win+Tab. Additionally, I want to map Win+[Arrows] to work for navigating between the windows in the Task Switcher.
This is achieved with the snippet below:
LWin & Tab:: AltTab
LWin & Right:: AltTab
LWin & Left:: ShiftAltTab
However, this triggers the Alt Tab functionality even when trying to organize windows. For example, when typing Win+Left I'd want to send the active window to the left side of the screen.
So the question is: How do I preserve the Win+[Arrow] functionality when I am not alt-tabbing?
Try this
; LWin + Tab = AltTab
<#Tab::
Send, {Alt Down}{Tab}
KeyWait, LWin ; waits for LWin to be relesead
Send, {Alt Up}
return
; LWin + LShift + Tab = ShiftAltTab
<#<+Tab::
Send, {Alt Down}{Shift Down}{Tab}
KeyWait, LWin
KeyWait, LShift
Send, {Alt Up}
return
#IfWinActive Task Switching
*Right:: Send {Right}
*Left:: Send {Left}
#IfWinActive
Wildcard (*): Fires the hotkey even if extra modifiers are being held down
With #user3419279's suggestion I got to this final solution:
LWin & Tab:: AltTab
#IfWinActive Task Switching
*Right:: AltTab
*Left:: ShiftAltTab
*Up::^Up
*Down::^Down
#IfWinActive
This allows me to move vertically and horizontally alongside many windows

Send Keypress to specific window/programm only

I have a Script that toggle a source in SLOBS (OBS), how can I make it that the keypress get only send to OBS, mostly my games also react to the Hotkeys, maybe it's possible to get the keypress only send to OBS so that the game is not affected by it, is this possible my actual script:
#Persistent
SetTimer, PressTheKey, 1800000
Return
PressTheKey:
Send, {F24 down}
Sleep, 50
Send, {F24 up}
Sleep, 10000
Send, {F24 down}
Sleep, 50
Send, {F24 up}
return
You need to use ControlSendRaw.

AutoHotkey - capture a hotkey combination in one application only - do not prevent other apps from using same combination

I have created a hotkey that I want to use only in MS Teams (workaround for the lack of 'Reply to message' function).
I assigned it to Ctrl+R, however it seems that it prevents other applications that use the same combination from noticing the hotkey.
The code is below:
^r::
if WinActive("ahk_exe Teams.exe")
{
SoundBeep 200,500
Send, ^c
Send, {Tab}
Send, >
Sleep, 500
Send, ^v
Send, {Enter}
Send, {Enter}
}
return
Is there a way to tell AHK to let the key combination bubble up when the active app is NOT teams?
I tried adding an 'else' clause in which I would Send, ^r but that didn't work.
Actually, I got it. Posting the working solution.
It seems I needed to wrap the hotkey declaration within the #ifwinactive directive.
#IfWinActive("ahk_exe Teams.exe")
^r::
SoundBeep 200,500
Send, ^c
Send, {Tab}
Send, >
Sleep, 500
Send, ^v
Send, {Enter}
Send, {Enter}
return
#IfWinActive
An even better, comprehensive solution and more powerful approach by #ThierryDalon - https://github.com/tdalon/ahk/blob/master/Lib/Teams.ahk
https://tdalon.blogspot.com/2020/11/teams-shortcuts-smart-reply.html

Solution to AHK sending too many events when holding down a mouse button?

When using three different methods of holding down the left mouse button:
Mouseclick, left, 0, 0, 1, , D, R
or
Send {LButton down}
or
Click down
the game I'm making a macro for logs me out complaining that I'm sending too many actions. I tested this by itself as a script, like:
F3::
Click down
return
So there's no chance other code is causing it.
I was wondering if there are any settings I can use (by settings I mean like CoordMode, Mouse, Screen) or any other solution to perhaps prevent whatever rapid event sending AHK is using to simulate a mouse button being held down. Is there any possible fix I can try? I'm open to testing any ideas.
Well, you could introduce a Sleep like so:
LButton::
while (GetKeyState("LButton", "P"))
{
MouseClick, left
Sleep, 100
}
return
Though I personally dislike binding the mouse click to behaviours via the same mouse click, as it can lead to results that are difficult to get out of.
Here's an example with a toggleable hotkey.
Insert::
SendInput, {LButton Down}
loop
{
Sleep, 100
if getkeystate("Insert", "p") ; Hold for a second as the Sleep will delay recognition.
{
SendInput, {LButton Up}
break
}
}
return
Edited per the comments:
Insert::
SendInput, {LButton Down}
KeyWait, Insert, D
SendInput, {LButton Up}
return

Mapping 2 different results to the same key

I'm kinda new at this. I have a mouse with only 3 keys that I'd like to write a script for to allow me to use the right mouse button like a "browser back" key if clicked, while still retaining the original function if held for a longer period of time.
RButton::
sleep 400
GetKeyState, state, RButton
if state = U
send {Browser_Back}
else
send {RButton}
keywait, RButton
return
Currently, all my script above does now is activates the "browser back" function, regardless of time held down. I think there's a problem with the key being repeated at the send {RButton} line, but adding a $ to RButton:: didn't seem to help (if it was supposed to, idk.) If I replace the 3 "RButton" instances (not including the one on the send line) with a key on the keyboard, it works perfectly though. Help would be appreciated. Thanks.
Adjusted the code from BlackHolyMan's response to fix it. In case anybody was curious or wanted it, here it is:
RButton::
KeyWait, RButton, U T0.5
If !ErrorLevel
{
send {Browser_Back}
return
}
else
{
send {RButton Down}
KeyWait, RButton
send {RButton up}
}
return
Hi this may be just about what you need
RButton::
KeyWait, RButton, U T0.5
If !ErrorLevel
send {Browser_Back}
else
{
send {RButton Down}
KeyWait, RButton
send {RButton up}
}
return
Still some things you may need to fix as i did not test it for long...