Hey there
Sorry if this is being repeated for the thousandth time, because it probably is but i can't seem to get the answer to my situation, so basically I need my XButton1 to perform in the following way,
If Pressed, Behavior 1
If Held, Behavior 2 it acts as if Ctrl key is being held, allowing me to then drag a selection box (which requires LButton to be held as well of course) over files (non contiguous selection), Ideally this would start after some time has elapsed since XButton1 was held, say 500 ms
So just to phrase it in another manner, as long as XButton1 is held it acts like Ctrl key is held; and when tapped it should perform another action.
I know I'm further complicating things by asking this, but can the above be integrated with Double Pressing XButton1 as a third hotkey
Thank you
Pressing X Triggers A, Holding X Triggers B
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
You're right. Some earlier examples are below.
viewtopic.php?p=227361#p227361
viewtopic.php?f=76&t=83364&p=364993#p364993
For your Ctrl, you can Send {Ctrl down}, then KeyWait for your other key, and then send your Ctrl up again.
viewtopic.php?p=227361#p227361
viewtopic.php?f=76&t=83364&p=364993#p364993
For your Ctrl, you can Send {Ctrl down}, then KeyWait for your other key, and then send your Ctrl up again.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
hi mikey and thanks for the quick response
i tried the following:
But this results in an error stating ELSE with no matching IF
i tried the following:
Code: Select all
$a::
If !Ta
SetTimer, Ta, -300
Ta++
Return
Ta:
If GetKeyState("XButton1","P")
Send {Ctrl down}
KeyWait XButton1
Send {Ctrl up}
Else If Ta = 2
Send, b
Else If Ta = 1
Send, a
KeyWait, XButton1
Ta =
Return
Last edited by koolestani on 28 Nov 2021, 05:20, edited 2 times in total.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
and weirdly enough this code snippet leads to the same result (types out Regular when tested in notepad) regardless of whether XButton1 was pressed once, twice or held down
Code: Select all
XButton1::
KeyWait, %A_ThisHotkey%, T0.2 ; Wait for release
If ErrorLevel { ; Button was HELD instead
SoundBeep, 1500, 20
Send Held `
Return
}
KeyWait, %A_ThisHotkey%, D T0.2 ; Wait for second press
If Errorlevel { ; Second press did not occur = REGULAR click
SoundBeep, 1200, 20
Send Regular `
Return
}
SoundBeep, 900, 20 ; Second press occurred = DOUBLE-click
Send Double `
Return
Re: Pressing X Triggers A, Holding X Triggers B
I just tested this exact script in Notepad, and it worked perfectly. Did you save and reload? This is your exact script, with no other code? You have no other scripts running? What AHK version do you run, and what operating system?
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
I did save and reload, this is the entire code no; extra code anywhere, i did have other scripts running earlier so i tried after pausing them and nothing changed then i tried after closing them and nothing changed, I'm on Windows 10 Version 20H2 (OS Build 19042.1320) 64bits, AutoHotkey Version 1.1.30.01
Last edited by koolestani on 28 Nov 2021, 10:43, edited 1 time in total.
Re: Pressing X Triggers A, Holding X Triggers B
Strange! A fix for the first script is below.
Code: Select all
XButton1::
If !Ta
SetTimer, Ta, -300
Ta++
Return
Ta:
Switch
{ Case GetKeyState("XButton1", "P"): SendInput Held`n
Case Ta = 2 : SendInput Double`n
Case Ta = 1 : SendInput Single`n
}
KeyWait, XButton1
Ta =
Return
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
Error at line 7.
Line Text: Switch
Error: This line does not contain a recognized action.
Line Text: Switch
Error: This line does not contain a recognized action.
Re: Pressing X Triggers A, Holding X Triggers B
It sounds like you are using an old AHK version. Would upgrade to the latest.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
Hi, sorry for the late response, I updated to the latest version and although the script doesn't throw the error it did previously. The "held" part just doesn't work, single and double are working fine. However this seems to be the case with XButton1, i replaced XButton1 with a and all three types of inputs are getting detected.
Re: Pressing X Triggers A, Holding X Triggers B
I presume that you are testing this exact script with no other code, and no other scripts running. It could be something different about how your mouse device is handling that button. When the button is pressed, the timer routine executes after 300 ms. If GetKeyState is set at that time, then the button is held. This is straightforward. You might want to see whether AHK can identify the key state for your button, via GetKeyState as well as KeyWait. Another possibility is that the button is firing repeatedly, but that would be unexpected.
You can determine what is happening in the Switch by displaying values of your key states & variables.
You can determine what is happening in the Switch by displaying values of your key states & variables.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
I was beginning to think so too, it's either at the hardware level or perhaps the accompanying software that acts as an obstacle in detecting the held state, either way i need to adapt. any ideas on how i can make double press of XButton1 toggle Ctrl held down/released?
Re: Pressing X Triggers A, Holding X Triggers B
Code: Select all
XButton1::
^XButton1::
If !Ta
SetTimer, Ta, -300
Ta++
Return
Ta:
Switch
{ Case GetKeyState("XButton1", "P"): SendInput Held`n
Case Ta = 2 : Send % "{Ctrl " (GetKeyState("Ctrl") ? "up" : "down") "}"
SoundBeep, 1000 + 500 * GetKeyState("Ctrl")
Case Ta = 1 : SendInput Single`n
}
KeyWait, XButton1
Ta =
Return
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
Thank you so much mikey, this is working liking a charm , i took the liberty of adding a triple click to toggle Shift key into this script as follows:
It is able to toggle Shift on but not off.
Code: Select all
Case Ta = 3 : Send % "{Shift " (GetKeyState("Shift") ? "up" : "down") "}"
SoundBeep, 1000 + 500 * GetKeyState("Shift")
Re: Pressing X Triggers A, Holding X Triggers B
I think you would need to add hotkey +XButton1 at the top.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
Thank you again. As you can probably see, i don't have the slightest clue about what's going on, so forgive me for asking too much. In mikey we trust.
Re: Pressing X Triggers A, Holding X Triggers B
It's Rohwedder's routine. Ta just increments by one with each button press. After 300 ms elapse, the main section executes, and then resets the counter. You need the extra hotkey because you want the routine to trigger even when Shift is down.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
Thank you for the quick and short, I'm just too illiterate in AHK syntax to make things happen, I get the general idea and feel of what the code is doing, but that's not enough to write my own scripts.
Re: Pressing X Triggers A, Holding X Triggers B
Keep at it. This one is not necessarily a "beginner" kind of a script. Look at examples & documentation whenever you have time! Learn by doing.
-
- Posts: 76
- Joined: 15 Jun 2020, 04:22
Re: Pressing X Triggers A, Holding X Triggers B
Thanks again!
Is there any way to remove the sound beep with a tooltip that stays on while the toggle is on and vice versa?
Is there any way to remove the sound beep with a tooltip that stays on while the toggle is on and vice versa?