Pregunta

Could someone help me with AutoHotKey Macro to have Q button pressed and released when right mouse button is clicked and Q button pressed and released when right mouse button is released?

Edit:
Explanation, imagine, that I am playing a game, and when i click right mouse button down (then I hold it) i need to have Q letter auto pressed on the keyboard, so I would get a jump(or crouch) in game at that time and when i release the right mouse button (mouse button up) i would get Q auto pressed again. I was trying to write the script and I couldn't get it working.

This is what I came up so far:

    RButton::
    If !Toggler {
    Send, {RButton Down} q
    Return
    }
    Send {RButton Up} q
    Return
¿Fue útil?

Solución

OK it looks like you want to toggle the behaviour.

#SingleInstance Force
#installKeybdHook
#Persistent
SetTitleMatchMode, 2 ; Make search title in #IfWinActive more flexible

#IfWinActive, Title of your game as found by AHK Windows Spy 
    RButton::
        If (Toggler := !Toggler )
        {
            ToolTip, RButton Down
            Send, {RButton Down} q
            Return
        }
        ToolTip, RButton Up        
        Send {RButton Up} q
    Return
#IfWinActive
Return

*x::
ExitApp

Update

After reading your text (and ignoring your script where you want to toggle the behaviour), I think that you want this! RightClick will send RightClick Down + q, then nothing, until you let go of RightClick, which will then send a RightClick Up + q. I added the ToolTips, so you can see if the script is activated correctly by #IfWinActive.

#SingleInstance Force
#installKeybdHook
#Persistent
SetTitleMatchMode, 2 ; Make search title in #IfWinActive more flexible

#IfWinActive, Title of your game as found by AHK Windows Spy

RButton::
    ToolTip, RButton Down + q
    Send, {RButton Down} q
Return

RButton Up::
    ToolTip, RButton Up + q
    Send, {RButton Up} q
Return

#IfWinActive
Return

*x::
ExitApp

If this is indeed what you want, then the final solution is coming pretty close to the original tip from Armin!

Update 2, Alternative way

#SingleInstance Force
#installKeybdHook
#Persistent
SetTitleMatchMode, 2 ; Make search title in #IfWinActive more flexible

#IfWinActive, Title of your game as found by AHK Windows Spy
    *~RButton:: ; ~ passes Rbutton through
        ToolTip, RButton Down + q
        Send, q
        KeyWait, RButton ; Wait for RButton to be released
        ToolTip, RButton Up + q
        Send, q
    Return
#IfWinActive
Return

*x::
ExitApp

Otros consejos

You can use the suffix up wit a hotkey.

Example

h up::
    ; your code
return

Will trigger when you release key h. You can use this with any hotkey including mouse.

You can use Send command for sending key presses.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top