Script for different combinations of mouse clicks (2024)

  • Board indexAutoHotkey (v2, current version)Ask for Help (v2)Gaming
    • It is currently 04 Jun 2024, 15:38
    • All times are UTC-05:00

Forum rules

Post Reply

  • Email topic
  • Print view

12 posts• Page 1 of 1

jooolius
Posts: 8
Joined: 03 Mar 2023, 19:16

Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 03:27

Hi, trying to write/look for a script that will do different things depending on what combination of mouse clicks/behaviors are done. The combinations I've been trying to get working specifically are:

  • double right click does something
  • double left click does something
  • holding right click does something
  • right-left click does something

I got a bit of a janky script working based on stuff I've found, but sometimes it behaves strangely and I'm not sure why. I'd ideally like the script to not affect regular single clicks, ie. you can left and right click normally while the script is running. I'd also extremely appreciate explanations as to how the code works, as I'd love to learn. Thank you in advance.

Top

boiler
Posts: 17304
Joined: 21 Dec 2014, 02:44

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 05:45

Before, you posted in this v2 section even though you were using v1. Are you still using v1 or are you now looking to write v2 code?

Top

jooolius
Posts: 8
Joined: 03 Mar 2023, 19:16

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 07:03

I'm mostly familiar with v1 scripts, but I'm open to using and learning v2 scripts, unless there's some kind of limitation or issue that would prevent me from doing so? Sorry, not super familiar with the differences between the versions but I figured I might as well try to ask about and use v2.

Top

Noitalommi_2
Posts: 300
Joined: 16 Aug 2023, 10:58

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 11:35

Hi.

I found this quite tricky, it took me a while until everything worked.
The double click timing is pretty short and since I didn't know what you wanted to send, I inserted SendText for all actions.
Actions are:
LB or RB single click, double click, held and both buttons held.

Code: Select all

#Requires AutoHotkey 2.0#SingleInstance; press F4 to exit the script!#HotIf !GetKeyState("RButton", "P")*LButton::#HotIf !GetKeyState("LButton", "P")*RButton:: {if ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 200SetTimer(Single, 0), Double()else if KeyWait(SubStr(ThisHotkey, 2), "T0.2")SetTimer Single, -100else Held()Single() {if A_ThisHotkey = "*LButton" {SendText "(Single click LButton)"}else {SendText "(Single click RButton)"}}Double() {if A_ThisHotkey = "*LButton" {SendText "(Double click LButton)"}else {SendText "(Double click RButton)"}}Held() {if GetKeyState("LButton", "P") && GetKeyState("RButton", "P") {SendText " (Both buttons held)"KeyWait("LButton")KeyWait("RButton")return}if A_ThisHotkey = "*LButton" {SendText "(LButton held)"KeyWait(SubStr(ThisHotkey, 2))}else {SendText "(RButton held)"KeyWait(SubStr(ThisHotkey, 2))}}}#HotIf*LButton::*RButton::returnF4::ExitApp

Top

jooolius
Posts: 8
Joined: 03 Mar 2023, 19:16

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 14:13

Thank you for this, I was planning on having each combination send a different key press, which is something that I could modify pretty easily. I do have a couple of questions regarding the script though.

  • Would you mind explaining what the #HotIf and SetTimer lines do? I can't really wrap my head around them just by reading the documentation.
  • Is it possible to make it so that the left mouse button behaves normally while the script is running? I don't need the script to do anything if I hold left click, and I'd like to still be able to hold left click to drag things around
  • I also would like the single right click to behave as normal
  • How would I add functionality for a right click -> left click to do something?

so basically I'd like to script to behave as follows:

  • single left click: normal behavior
  • single right click: normal behavior
  • hold left click: normal behavior
  • hold right click: do something
  • double left click: do something
  • double right click: do something
  • right into left click: do something

Noitalommi_2 wrote:

Yesterday, 11:35

Hi.

I found this quite tricky, it took me a while until everything worked.
The double click timing is pretty short and since I didn't know what you wanted to send, I inserted SendText for all actions.
Actions are:
LB or RB single click, double click, held and both buttons held.

Code: Select all

#Requires AutoHotkey 2.0#SingleInstance; press F4 to exit the script!#HotIf !GetKeyState("RButton", "P")*LButton::#HotIf !GetKeyState("LButton", "P")*RButton:: {if ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 200SetTimer(Single, 0), Double()else if KeyWait(SubStr(ThisHotkey, 2), "T0.2")SetTimer Single, -100else Held()Single() {if A_ThisHotkey = "*LButton" {SendText "(Single click LButton)"}else {SendText "(Single click RButton)"}}Double() {if A_ThisHotkey = "*LButton" {SendText "(Double click LButton)"}else {SendText "(Double click RButton)"}}Held() {if GetKeyState("LButton", "P") && GetKeyState("RButton", "P") {SendText " (Both buttons held)"KeyWait("LButton")KeyWait("RButton")return}if A_ThisHotkey = "*LButton" {SendText "(LButton held)"KeyWait(SubStr(ThisHotkey, 2))}else {SendText "(RButton held)"KeyWait(SubStr(ThisHotkey, 2))}}}#HotIf*LButton::*RButton::returnF4::ExitApp

Top

Noitalommi_2
Posts: 300
Joined: 16 Aug 2023, 10:58

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 22:16

@jooolius

The thing is, I don't know if it bothers your game if the initial click of a double click comes through. Because otherwise every double click would send a single click first.
I tried to solve this with SetTimer, i.e. to give the script time to differentiate. Thats also why there is a short delay for single clicks, but i don't have a better solution right now.
#Hotif is there so that the hotkeys don't trigger each other when you hold both keys.

Please try this:

Code: Select all

#Requires AutoHotkey v2.0#SingleInstance; press F4 to exit the script!#HotIf !GetKeyState("RButton", "P")*LButton::#HotIf !GetKeyState("LButton", "P")*RButton:: {if ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 200SetTimer(Single, 0), Double()else if KeyWait(SubStr(ThisHotkey, 2), "T0.2")SetTimer Single, -100else Held()Single() => SendEvent("{" SubStr(A_ThisHotkey, 2) "}") ; single left/right click: normal behaviorDouble() {if A_ThisHotkey = "*LButton" {SendText "(Double click LButton)" ; double left click: do something}else {SendText "(Double click RButton)" ; double right click: do something}}Held() {if A_ThisHotkey = "*LButton" { ; hold left click: normal behaviorSendEvent "{LButton down}"KeyWait "LButton"SendEvent "{LButton up}"}else {while GetKeyState("RButton", "P") {if GetKeyState("LButton", "P") {SendText "(right into left click: do something)" ; right into left click: do somethingreturn}}}}}#HotIf*LButton::return*RButton::returnF4::ExitApp

Top

jooolius
Posts: 8
Joined: 03 Mar 2023, 19:16

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 22:39

hmmm I see, would it simplify the script if the initial click for every double click goes through? Because I think that would be fine. Also, sorry for the confusion but would it be possible to make it so that it was a full right click, then a full left click that triggers something? Not a hold right click into a left click.

Top

jooolius
Posts: 8
Joined: 03 Mar 2023, 19:16

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Yesterday, 23:20

Ok, tried starting fresh using some of the stuff in the code you made, and got this:
#Requires AutoHotkey v2.0

Code: Select all

Esc::ExitApp; press Esc to exit the script!~RButton::{ if (!KeyWait("RButton", "T0.15")) { SoundBeep 250, 150 Send "(RB HOLD)" } ; this doesn't work else if (A_PriorHotkey = '~RButton' and A_TimeSincePriorHotkey < 200) { SoundBeep 600, 250 Send "(RB DOUBLE)" }}~LButton::{ if (A_PriorHotkey = '~LButton' and A_TimeSincePriorHotkey < 200) { SoundBeep 250, 150 Send "(LB DOUBLE)" } else if (A_PriorHotkey = '~RButton' and A_TimeSincePriorHotkey < 200) { SoundBeep 1500, 250 Send "(RB LB)" }}

which behaves very closely to how I would like it to, the only problem is that the double right click checking doesn't seem to work and I'm not sure how to fix it.

Top

Noitalommi_2
Posts: 300
Joined: 16 Aug 2023, 10:58

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Today, 08:43

jooolius wrote:

Yesterday, 22:39

hmmm I see, would it simplify the script if the initial click for every double click goes through?

Yes, that would simplify the script.

jooolius wrote:

Yesterday, 23:20

... the only problem is that the double right click checking doesn't seem to work and I'm not sure how to fix it.

Do the "if" check for the double click first and then the "else if" for the KeyWait.

Top

Rohwedder
Posts: 7742
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Today, 11:33

Hallo,
if the single click is to go through and only something is to be sent with the double clicks:

Code: Select all

#Requires AutoHotkey v2.0Triple("~LButton", 300,, "Hello ",, "ahk_class Notepad")Triple("~RButton", 300,, "{Esc}World ",, "ahk_class Notepad")/*Triple("+F2", 300, "1", "2", "^a")Triple("$Space", 300, "{Space}", "`t", "{Bs}", "ahk_class Notepad")Triple("$Enter", 300, "{Enter}", "To whom it may concern,{Enter 2}", "{Enter 2}Yours sincerely,", "ahk_exe WINWORD.EXE")*/Triple(TripleKey, msec:=400, singleKey:="", doubleKey:="", holdKey:="", activeWin:="") { ProcessPress(key) { Static N := 0 held := True, ++N AfterTime() { Send(held?holdKey:(N=1)?singleKey:doubleKey), N := 0 } If (N = 1) { SetTimer AfterTime, -msec KeyWait RegExReplace(TripleKey, ".*?(\W$|\w*$)", "$1") held := False } } HotIf (*) => activeWin?WinActive(activeWin):True Hotkey TripleKey, ProcessPress}

Top

jooolius
Posts: 8
Joined: 03 Mar 2023, 19:16

Re: Script for different combinations of mouse clicks

  • @
  • Quote

Today, 11:35

huge, thank you!

Top

Post Reply

  • Email topic
  • Print view

12 posts• Page 1 of 1

Return to “Gaming”

Jump to

  • AutoHotkey Foundation
  • About This Community
  • Forum Issues
  • AutoHotkey (v2, current version)
  • Ask for Help (v2)
  • Gaming
  • Scripts and Functions (v2)
  • Gaming
  • Tutorials (v2)
  • Tips and Tricks
  • Wish List
  • Suggestions on Documentation Improvements
  • Bug Reports
  • AutoHotkey Development
  • AutoHotkey_H
  • Ask for Help
  • Development
  • Editors
  • Adventure IDE
  • Old Topics
  • AHK Studio
  • Notepad++
  • Pulovers Macro Creator
  • SciTE4AutoHotkey
  • Visual Studio Code
  • Announcements
  • General Discussion
  • AutoHotkey (v1.1 and older)
  • Ask for Help (v1)
  • Gaming Help (v1)
  • Scripts and Functions (v1)
  • Gaming Scripts (v1)
  • Tutorials (v1)
  • Tips and Tricks (v1)
  • General
  • Other Programming Languages
  • C/C++
  • ASM
  • C#
  • KeySharp
  • Off-topic Discussion
  • RPA
  • Other languages
  • Looking for Volunteers in other languages
  • Deutsch (German)
  • Ich brauche Hilfe
  • Spiele
  • Skripte und Funktionen
  • Tutorials
  • Tooltime
  • Allgemeines
  • 中文 (Chinese)
  • 请求帮助
  • 脚本函数
  • 教程资料
  • 相关工具
  • 其他
  • Español (Spanish)
  • Pedir Ayuda
  • Automatización de Juegos
  • Scripts y Funciones
  • Tutoriales
  • Otras Utilidades y Recursos
  • General
  • Русский (Russian)
  • Помощь
  • Скрипты для Игр
  • Скрипты и библиотеки
  • Статьи и руководства
  • Прочие ресурсы и ПО.
  • Свободное общение
  • Français (French)
  • J'ai besoin d'aide
  • Scripts et Fonctions
  • Tutoriels
  • Autres Utilitaires et Ressources
  • Hors Sujet
  • Português (Portuguese)
  • Ajuda e Suporte Geral
  • Scripts e Funções
  • Tutoriais
  • Outras Ferramentas e Recursos
  • Outros Assuntos
  • 한국어 (Korean)

Who is online

Users browsing this forum: No registered users and 10 guests

Script for different combinations of mouse clicks (2024)
Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6193

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.