Long press right mouse key to send alt f4

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Long press right mouse key to send alt f4

11 Oct 2021, 04:26

Hello, I'm trying to make a long press on the right mouse button (like half a second or so) to perform as alt+F4. I have similar functions with the mouse but can't figure this one out. This is what I have.

Code: Select all

$*rbutton::
Send {Blind}{rbutton}
KeyWait, rbutton, T0.4
If ErrorLevel {
	Send {!f4}
	KeyWait, rbutton
}
return
[Mod edit: [code][/code] tags added.]

Can anyone tell me what's wrong?
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Long press right mouse key to send alt f4

11 Oct 2021, 05:47

The Alt modifier ! is not part of the F4 key name, so it doesn’t belong inside the braces with it:

Code: Select all

Send, !{F4}
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press right mouse key to send alt f4

12 Oct 2021, 05:12

Yeah I noticed that right after posting this but it still doesn't work. The script works with a keyboard key but not the right mouse button. :\
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Long press right mouse key to send alt f4

12 Oct 2021, 06:11

See if this works.
Pressing the button starts a counter that stops when the button is released, if it is shorter than set, the condition of sending the keyboard shortcut does not work.

Code: Select all

~+LButton::start := A_TickCount
~+LButton Up::
If (A_TickCount - start < 1200)
  Return
Send {!f4}
Return
The sign "~" gives priority to this keyboard proces.
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Long press right mouse key to send alt f4

12 Oct 2021, 06:12

@sulphuricsaliva — I’m away from a computer with a physical mouse right now, so I can’t test it. Try replacing the Send with a MsgBox just to isolate the problem (i.e., to eliminate the possibility that the Send !{F4} is getting executed but doesn’t send correctly while the right mouse button is held down).
wetware05
Posts: 750
Joined: 04 Dec 2020, 16:09

Re: Long press right mouse key to send alt f4

12 Oct 2021, 09:09

Hi boiler.

I don't know if it's Send {!f4} 0 Send ! {f4}. I just copied and pasted. Sorry

by the way, what button (option) in the post editor makes a text come out inside a square?

The script above was taught to me by mikeyww, I forgot to mention it.
Last edited by wetware05 on 13 Oct 2021, 06:39, edited 4 times in total.
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press right mouse key to send alt f4

12 Oct 2021, 15:44

I really appreciate the effort but still doesn't work. I've had trouble creating hotkeys with rmouse before...
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Long press right mouse key to send alt f4

12 Oct 2021, 17:52

wetware05 wrote: by the way, what button (option) in the post editor makes a text come out inside a square?
Use the Code tag button </>.
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press right mouse key to send alt f4

13 Oct 2021, 12:55

Wow that script is very confusing. Anyway, the problem here is specifically about the rbutton. Any other button or key works.
ceyhunveysel
Posts: 52
Joined: 02 Aug 2019, 15:39

Re: Long press right mouse key to send alt f4

13 Oct 2021, 17:16

You can do a ~RButton:: (see Hotkey) and Sleep as much as you want, then check again using GetKeyState if right click is still being pressed, and then maybe use WinKill, A (standing for Active) if you want to kill the active app (it does the same thing as a ALT+F4)
signature C:
ceyhunveysel
Posts: 52
Joined: 02 Aug 2019, 15:39

Re: Long press right mouse key to send alt f4

13 Oct 2021, 17:17

I can probably try making a script for this, but I don't want to write a script for another person (because asking someone to make an ahk script for you on a autohotkey forum is kind of lame, lol)
signature C:
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press right mouse key to send alt f4

14 Oct 2021, 04:55

ceyhunveysel aren't you sweet. :dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Bing [Bot], Google [Bot], peter_ahk and 347 guests