I want a script where pressing F1 makes AutoHotkey hold down the left mouse button. I then want the script to release the mouse once I press the key again.
How can I do that?
I would use Click down and Click up
Click is generally preferred over MouseClick because it automatically compensates if the user has swapped the left and right mouse buttons via the system's control panel.
F1::
alt := not alt
if (alt)
{
Click down
}
else
{
Click up
}
Return
Here is a one-liner in case anyone is interested:
F1::Click % GetKeyState("LButton") ? "Up" : "Down"
Mmm, I am a bit rusty in AHK programming, but here is what I tried, seems to work:
F1::
alt := not alt
If (alt)
{
MouseClick Left, 217, 51, , , D
}
Else
{
MouseClick Left, 217, 51, , , U
}
Return
Related
I am attempting to write AutoHotkey code that results in sending the Space key when the Left Mouse Button is clicked at some position in the screen (ranges shown below). If the mouse is clicked outside the range, it should result in default behavior. The code below is not working. Example, if I click the Application's Close button whose ypos is less than 170, nothing happens. Request help/inputs. Thanks.
#IfWinActive ahk_class IrfanView
LButton::
MouseGetPos,xpos, ypos
If (ypos >170 and ypos <570)
{
Msgbox %ypos%
Send, {Space}
}
#IfWinActive
Return
You almost had it.
Since, you are handling the left mouse click, nothing further will happen mouse-wise.
So you have to re-issue the click event like this:
#IfWinActive ahk_class IrfanView
LButton::
MouseGetPos, xpos, ypos
If (ypos >170 and ypos <570) {
Msgbox %ypos%
Send, {Space}
}
Else {
Click
}
Return
Also note I removed your second #ifWinActive
That shouldn't happen before the return statement.
If you are only adding hotkeys for IrfanView, then that statement won't be necessary at all. If, like me, you are trapping keys for different windows/programs all in one big script, then follow a pattern like this
#IfWinActive ahk_class CabinetWClass ;Windows Explorer
...keydefs here...
#IfWinActiveahk_class XLMAIN ;Excel
...keydefs here...
#IfWinActive ahk_exe OUTLOOK.exe ;Outlook
...keydefs here...
#IfWinActive ;Keys that work anywhere
...all other keydefs here...
I want to change same lines at the same time.
for example I want to change { backgroundColor: '#fff' } at anywhere on my file.js. (I don't want to use Replace)
Select { backgroundColor: '#fff' } with your mouse and press cmd + shift + L (or ctrl + shift + L) to select all occurrences of it in your file. Then, you can change them all at the same time.
Try
Ctrl + F (backgroundColor: '#ufff')
Alt + Enter
This will select every instance and give each an active cursor. Hit Esc to exit multi cursor mode.
I want to detect double press on AltGr.
According to documentation:
; Example #4: Detects when a key has been double-pressed (similar to double-click).
; KeyWait is used to stop the keyboard's auto-repeat feature from creating an unwanted
; double-press when you hold down the RControl key to modify another key. It does this by
; keeping the hotkey's thread running, which blocks the auto-repeats by relying upon
; #MaxThreadsPerHotkey being at its default setting of 1.
; Note: There is a more elaborate script to distinguish between single, double, and
; triple-presses at the bottom of the SetTimer page.
~RControl::
if (A_PriorHotkey <> "~RControl" or A_TimeSincePriorHotkey > 400)
{
; Too much time between presses, so this isn't a double-press.
KeyWait, RControl
return
}
MsgBox You double-pressed the right control key.
return
AltGr is actually a combination of LControl & RAlt. So, for AltGr, script should be something like this:
~LControl & RAlt::
if (A_PriorHotkey <> "~LControl & RAlt" or A_TimeSincePriorHotkey > 400)
{
click
KeyWait, LControl & RAlt
return
}
click 2
return
But when I try to load this script, AutoHotkey gives an error:
Maybe there is a way to make an alias for key combinations.
As mentioned in the comments, KeyWait can only wait on one key (not hotkey) at a time. You only need to wait for RAlt to be released, not the combination of LCtrl and RAlt.
This works:
~LControl & RAlt::
if (A_PriorHotkey <> "~LControl & RAlt" or A_TimeSincePriorHotkey > 400)
{
KeyWait, RAlt
return
}
MsgBox Double-click
return
However, in this case KeyWait is only being used (in combination with the default #MaxThreadsPerHotkey setting of 1) to prevent key-repeat from activating the hotkey. You can remove KeyWait and it will still detect double-presses; but it will also activate if you hold AltGr down until it auto-repeats.
Note that in your case, double-pressing the hotkey would click three times: once on the first press and an additional two times on the second press.
If you just want to use AltGr as a mouse button and allow double-click, all you need is <^RAlt::Click.
If you want to perform two different actions depending on whether it is a single or double click, you must delay the response to the first click until you know whether there's a second click. For example:
<^RAlt::
KeyWait RAlt
KeyWait RAlt, D T0.4
if ErrorLevel
MsgBox Single
else
MsgBox Double
return
I would like to hold
alt + spacebar + U for the up key
alt + spacebar + H for the left arrow key
alt + spacebar + J for the right arrow key
alt +spacebar + N for the down arrow
is this possible to do with AutoHotkey?
Hello and welcome to AutoHotkey,
you might want to have a look at the basic introduction to the heart of AHK, Hotkeys:
https://www.autohotkey.com/docs/Hotkeys.htm
Configuring hotkeys which do nothing but send another key is fairly simple. For example, alt + spacebar for the up key could be translated into
!Space::
send {up}
return
(note that alt is a modifier and can be written as !)
or short form:
!Space::send {up}
spacebar + U for the up key would be Space & U::send {up}.
But you are seeking for 2 keys PLUS a modifier (alt). For a hotkeylabel triggered by more than just two keys (alt + space + u), you'll need a workaround:
!Space:: ; once alt + space was pressed, ...
while(getKeyState("alt") || getKeyState("space") || getKeyState("u")) { ; ... while either of these is being pressed down, ...
hotKey, *u, altSpaceU, ON ; u should now send {up}
}
hotKey, *u, altSpaceU, OFF
return
altSpaceU: ; note: this is a label, no hotkey
send {up}
return
Please, don't be undeterred by this. AutoHotkey is actually quite powerful and easy to learn. Sadly, (afaik) this is the only working way to solve more-than-two-key-hotkeys.
EDIT
jesus why didnt anybody tell me..
#if getkeystate("alt")
!space::send {up}
#if
is obviously a way better solution
this was the solution
!Space::
send {up}
return
up up down down left right left right b a enter :: Msgbox, konami code.
is there a way to do this?
yes its actually pretty simple...
comb := "up|down|down|left|right|left|right|b|a|enter"
~up::
Loop, parse, comb, |
{
input, var,T.900,{%a_loopfield%}
if inStr(ErrorLevel, "Timeout")
return
}
msgbox Konami Code!!!
return
The first "up" is the one that will trigger the sequence hence only one "up" in the combination variable.
you can change the combination to whatever you want, but then you would have to change the hotkey to the first "key" that you want to press.