Assign a function to a double middle click press? Topic is solved
Assign a function to a double middle click press?
How can I assign a function to a double middle click press?
I'm a total noob with AutoHotkey and I don't have any coding experience...
I'm a total noob with AutoHotkey and I don't have any coding experience...
Re: Assign a function to a double middle click press?
I'm not sure about your coding skills, so I've kept it as simple as possible for now.
Questions are always welcome.
Questions are always welcome.
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
i := 0
*MButton:: {
global i
++i
setTimer(check, -250)
}
check() {
global i
if (i == 2) {
tooltip("Double Middle Click")
setTimer(tooltip, -800)
; TO DO
} else {
click("Middle")
}
i := 0
}
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Assign a function to a double middle click press?
I was going to suggest this:
I think Seven's is probably better though. Mine prevents the MButton from being used for normal actions.
Code: Select all
#SingleInstance
#Requires AutoHotkey v2+
MButton::
{ IF (A_PriorHotkey = "MButton") and (A_TimeSincePriorHotkey < 200)
msgbox 'mbutton double click detected'
}
ste(phen|ve) kunkel
Re: Assign a function to a double middle click press?
@Seven0528
Ok man, thanks for fast reply!
So if I want for that 'double middle mouse click' to do 'Ctrl+Alt+Y' where/how do I put that in the script?
Ok man, thanks for fast reply!
So if I want for that 'double middle mouse click' to do 'Ctrl+Alt+Y' where/how do I put that in the script?
Re: Assign a function to a double middle click press?
Ah, I guess I put the combination in the 'TO DO' part...
Thanks again!
Thanks again!
Re: Assign a function to a double middle click press?
Code: Select all
; TO DO
Code: Select all
send("^!y")
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Assign a function to a double middle click press?
Argh... but using this script disables my StrokeIt mouse gestures software, which uses the middle mouse button for drawing (dragging) the gestures...
Re: Assign a function to a double middle click press?
That was the problem that I found as well.
Last edited by kunkel321 on 15 May 2024, 20:22, edited 1 time in total.
ste(phen|ve) kunkel
Re: Assign a function to a double middle click press?
*~MButton::
Hotkey Modifier Symbols
Hotkey Modifier Symbols
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
i := 0
*~MButton:: {
global i
++i
setTimer(check, -250)
}
check() {
global i
if (i == 2)
send("^!y")
i := 0
}
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Assign a function to a double middle click press?
If I don't consider beginners and write code at my full potential, it would look like this.
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
MButtonRemapping.InputIntervalTick := 250
#HotIf
*~MButton:: MButtonRemapping.onPress()
#HotIf MButtonRemapping.IsContinuousInput
*MButton:: MButtonRemapping.onPress(true)
#HotIf
class MButtonRemapping ; ahk2.0
{
static _pressedTick := 0
,_inputIntervalTick := this._doubleClickSpeed
,_pressedCount := 0
,_objbmResetCount := objBindMethod(this, "_resetCount")
static IsContinuousInput => (this._tickCount < this._pressedTick + this._inputIntervalTick)
static InputIntervalTick {
get => this._inputIntervalTick
set => this._inputIntervalTick := value
}
;--------------------------------------------
static onPress(keyBlocked := false) {
this._pressedTick := this._tickCount
++this._pressedCount, setTimer(this._objbmResetCount, -this._inputIntervalTick)
if (keyBlocked) {
switch (this._pressedCount)
{
case 2:
this._resetCount()
; TO DO
tooltip("Double Middle Click")
setTimer(tooltip, -800)
}
}
}
static _resetCount() {
this._pressedCount := 0
}
;--------------------------------------------
static _tickCount => (A_Is64bitOS ? this._tickCount64 : this._tickCount32)
static _tickCount32 => dllCall("Kernel32.dll\GetTickCount", "UInt") ; 0x0 to 0xFFFFFFFF
static _tickCount64 => dllCall("Kernel32.dll\GetTickCount64", "Int64") & 0x7FFFFFFFFFFFFFFF ; 0x0 to 0x7FFFFFFFFFFFFFFF
static _doubleClickSpeed => regRead("HKEY_CURRENT_USER\Control Panel\Mouse", "DoubleClickSpeed", 500)
}
Last edited by Seven0528 on 15 May 2024, 15:36, edited 1 time in total.
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Assign a function to a double middle click press?
@Seven0528
Now it almost works, but it does weird stuff:
1. After doing the double middle click, the next gesture drawn holding single middle click is not recognized. It works just a single middle click, it doesn't detect it as a button being held.
2. Keyboard starts behaving strange, backspace/delete doesnt work, arrow keys don't work...
Now it almost works, but it does weird stuff:
1. After doing the double middle click, the next gesture drawn holding single middle click is not recognized. It works just a single middle click, it doesn't detect it as a button being held.
2. Keyboard starts behaving strange, backspace/delete doesnt work, arrow keys don't work...
Re: Assign a function to a double middle click press?
BTW, I provided two pieces of code. Which one did you test?
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Assign a function to a double middle click press?
I tested both, the first code (short one) doesn't do the Ctrl+Alt+y when I double middle click.
The second one is the one that works... but has those weird side effects.
1. To do a mouse gesture with StrokeIt I hold middle click and drag it across the screen to 'draw' a gesture. StrokeIt makes a defined action depending on the gesture you draw. After doing a middle double click using your script, the next time I try to 'draw' a gesture holding middle click it doesn work, it just registers as if I pressed the button, NOT holding it to 'draw'. The next time after that then it works again.
2. Yes, the keyboard thing was pretty shocking... most non alphanumeric keys do not work: Enter, Tab, Backspace, arrows, Insert, Del, Home, End, Pag Up, Pag Down, ... but letters and number do work.
The second one is the one that works... but has those weird side effects.
1. To do a mouse gesture with StrokeIt I hold middle click and drag it across the screen to 'draw' a gesture. StrokeIt makes a defined action depending on the gesture you draw. After doing a middle double click using your script, the next time I try to 'draw' a gesture holding middle click it doesn work, it just registers as if I pressed the button, NOT holding it to 'draw'. The next time after that then it works again.
2. Yes, the keyboard thing was pretty shocking... most non alphanumeric keys do not work: Enter, Tab, Backspace, arrows, Insert, Del, Home, End, Pag Up, Pag Down, ... but letters and number do work.
Re: Assign a function to a double middle click press?
@Milincho
Sure, just to clarify, I didn't touch any keyboard-related parts in either the first or second code snippets I provided.
So, I genuinely share your confusion. However, I do have a suspicion that the state of the modifier keys sent via Send might be causing interference.
As for my original code without the Send command, it shouldn't cause any keyboard interference on its own, as I assumed.
I've just learned about StrokeIt myself.
While I'm curious to download it and test it out, it's not my top priority at the moment.
(Helping you has already taken up more time than I expected. Sorry.)
I might revisit this issue when I have more free time. Perhaps tomorrow? Or the day after? But it's not set in stone.
Could you provide a download link for StrokeIt? (I could find it myself, but...)
Also, could you explain in detail what Ctrl + Alt + Y does?
Sure, just to clarify, I didn't touch any keyboard-related parts in either the first or second code snippets I provided.
So, I genuinely share your confusion. However, I do have a suspicion that the state of the modifier keys sent via Send might be causing interference.
As for my original code without the Send command, it shouldn't cause any keyboard interference on its own, as I assumed.
I've just learned about StrokeIt myself.
While I'm curious to download it and test it out, it's not my top priority at the moment.
(Helping you has already taken up more time than I expected. Sorry.)
I might revisit this issue when I have more free time. Perhaps tomorrow? Or the day after? But it's not set in stone.
Could you provide a download link for StrokeIt? (I could find it myself, but...)
Also, could you explain in detail what Ctrl + Alt + Y does?
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Assign a function to a double middle click press?
@Seven0528
Sure, I'm very grateful for you spending your time trying to help me.
https://www.tcbmi.com/strokeit/ it's a very old freeware program. There are other newer mouse gestures programs like StrokesPlus.net, Gesturify and others, but time after time I find myself prefering StrokeIt for being light, fast and very easy to configure.
Ctrl+Alt+Y invokes a function I have configured in DisplayFusion to move the active window to the next monitor in a multi-display setup: Thanks again for your help, man!
Sure, I'm very grateful for you spending your time trying to help me.
https://www.tcbmi.com/strokeit/ it's a very old freeware program. There are other newer mouse gestures programs like StrokesPlus.net, Gesturify and others, but time after time I find myself prefering StrokeIt for being light, fast and very easy to configure.
Ctrl+Alt+Y invokes a function I have configured in DisplayFusion to move the active window to the next monitor in a multi-display setup: Thanks again for your help, man!
Re: Assign a function to a double middle click press?
A guy here https://superuser.com/questions/1513171/make-double-clicking-the-middle-button-do-something-special posted this answer to the question:
But that gave me errors.
I tried:
Which doesn't give errors, but do not work also... what am I doing wrong?
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Code: Select all
~MButton::
If(A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~MButton")
Send
Return
I tried:
Code: Select all
~MButton::
{
If(A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~MButton")
send("!^y")
}
[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]
Re: Assign a function to a double middle click press? Topic is solved
Are you sure it didn't give you an error? It should have if you ran it with AHK v2. Here's how to fix it:
Or not having to worry about the literal string in case you change the hotkey:
Code: Select all
#Requires AutoHotkey v2.0
~MButton::
{
If (A_PriorHotkey="~MButton") and (A_TimeSincePriorHotkey<400)
send("!^y")
}
Or not having to worry about the literal string in case you change the hotkey:
Code: Select all
#Requires AutoHotkey v2.0
~MButton:: {
if (A_PriorHotkey = A_ThisHotkey) && (A_TimeSincePriorHotkey < 400)
Send '!^y'
}
Re: Assign a function to a double middle click press?
@boiler
I see... yeah, your correction works but... it doesn't work properly detecting a double click. It send the keystroke with each single middle click, even if the previous one is from a different button or key.
I see... yeah, your correction works but... it doesn't work properly detecting a double click. It send the keystroke with each single middle click, even if the previous one is from a different button or key.
Re: Assign a function to a double middle click press?
I can’t see why it would do that. When I test it in a text editor and sending just the letter y instead of !^y so I can see visible proof, it works only after two quick clicks. Make sure you don’t have any other scripts running.
Re: Assign a function to a double middle click press?
@boiler
It was a conflict with StrokeIt. Using a different mouse gestures software it works ok now.
Thanks!
It was a conflict with StrokeIt. Using a different mouse gestures software it works ok now.
Thanks!