This is my code.
#InputLevel 1
LAlt::LWin
LWin::LAlt
#InputLevel 2
!a::
#a::
tooltip You pressed %A_ThisHotkey%.
return
From my understanding, InputLevel 2 is executed first, then InputLevel 1, which means if I press LAlt key and a key, screen will show I pressed !a, if I press LWin key and a key, screen will show I pressed #a.
However actually my screen shows nothing. My key is not captured.
Do I miss anything? I want to capture hotkey first then do remapping.
When you press alt + a the LAlt::LWin hotkey is being fired first and the !a:: hotkey is being ignored. If you want to fire the !a:: regardless of the first hotkey fired you must add ~ on the LAlt::LWin hotkey so its native function (necessary to perform alt+a) isn't going to be blocked.
It may be easier to understand with this example:
#InputLevel 1
~LAlt:: tooltip First pressed %A_ThisHotkey%.
~LWin:: tooltip First pressed %A_ThisHotkey%.
#InputLevel 2
!a::
#a::
tooltip Then pressed %A_ThisHotkey%.
return
ps: if you also want to ignore extra modifiers that are (maybe) being held down you can add the wildcard * on the !a:: and #a:: hotkeys. So, in the end, the hotkeys would look like this: ~LAlt::LWin ~LWin::LAlt *!a:: and *#a::
Related
I have this autohotkey script to make some media keys
RWin & AppsKey Up::Run calc1.exe
Pause::Media_Play_Pause
Ralt & F11::Media_Prev
Rcontrol & F11::Media_Prev
Ralt & F12::Media_Next
Rcontrol & F12::Media_Next
I'm trying to trigger previous and next track only once (if held),
I tried adding Up like I did with the AppsKey, but it doesn't work - it shows error when trying to run.
Interestingly Pause only triggers once.
And why can't I use CTRL+NUMLOCK? It actually triggers the Pause key...
Also, how do I assign a hotkey to the Wake key?
1,you can try this:
<!F11::
send {Media_Prev}
keywait F11
return
<!F12::
send {Media_Next}
keywait F12
return
here <! mean left alt key;
keywait is used to wait a key to to released
2,because
While Ctrl is held down, NumLock produces the key code of Pause, so use ^Pause in hotkeys instead of ^NumLock
(from https://www.autohotkey.com/docs/KeyList.htm#numpad)
here is code for test:
Pause::
tooltip you press "Pause"
return
NumLock::
tooltip you press "NumLock"
return
;ctrl+numlock
^pause::
tooltip you press "ctrl+numlock"
return
;ctrl+Pause
^CtrlBreak::
tooltip you press "ctrl+Pause"
return
3, I don't have "wake" key,so I cannot test it, you maybe can try this:
https://www.autohotkey.com/docs/KeyList.htm#SpecialKeys
Background: I'm trying to have a f-mode and d-mode which means if I press down the f key and press another key like i then nothing happens excepts a shortcut. let say it will send Up key instead of f and I.
Issue: how I can remap a pressed key (I in my example) to a shortcut (Up as example)?
Code:
d::
f::{
;...
loop{
if !GetKeyState("f","p") && !GetKeyState("d","p"){
break
}
if GetKeyState("i","p") {
OutputDebug "i"
send "{up}"
continue
}
; ...
}
}
Looks like you want to make a custom combination.
From the Docs:
You can define a custom combination of two keys (except joystick
buttons) by using " & " between them. In the below example, you would
hold down Numpad0 then press the second key to trigger the hotkey:
Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
Numpad0 & Numpad2::Run Notepad
But also note:
The prefix key loses its native function: In the above example,
Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its
original/native function when it is pressed by itself. To avoid this,
a script may configure Numpad0 to perform a new action such as one of
the following:
Numpad0::WinMaximize A ; Maximize the active/foreground window.
Numpad0::Send {Numpad0} ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.
This is to prevent holding down a key from spamming inputs while you wait to press the second part of a key combination. So essentially, your 'f' and 'd' keys will now perform their normal functions when you release them instead of initially pressing them down.
Anyways, the code would become:
f & i::
d & i::
Send {Up}
return
f::f
d::d
I want to make a script that would allow me to click once every time I press the mouse, however, if instead of letting go immediately, I hold the RMB for more than 0.25s it would click again on release.
Essentially allowing me to use RMB normally as long as I don't hold it for too long but allowing me to do a double click if held.
This is a work around since my mouse's button gets stuck if I click too fast and I'm not able to get a new one atm.
The purpose of this is to be able to use my mouse on PS and to play the one game i play some times: Black Ops 2 while i save enough for a new mouse. In the context of the game, i want to be able to use Toggle ADS as a base and be able to use the toggle by default by just clicking but be able also do a Hold to ADS with the same button on the fly without changing the game's configuration.
I am not very proficient at AHK and this is all I got so far, holding works fine, however if I don't hold, it does a double click which is annoying.
RButton Down::
Send {Click, Right}
keywait RButton, t.25
if errorlevel
keywait RButton,
Send {RButton Up}
return
You could maybe do some trickery with multiple KeyWaits, but I wouldn't recommend time consuming processing inside hotkey labels in any case due to AHKs single threaded nature.
Here's something very simple I'd recommend instead:
~*RButton::RClickTime := A_TickCount
~*RButton Up::
if (A_TickCount - RClickTime >= 250)
Click, Right
return
So first when we press down RButton (note that there is no "down" state for hotkey names, the key name itself means it being pressed down) we store the current system time with A_TickCount.
And we use the ~ modifier for the hotkey so the keypress itself isn't consumed.
And the * modifier is used so holding down e.g. Ctrl or Shift, etc, wouldn't make the hotkey not work.
Then on RButton release (RButton Up::) we compare the current system time with the stored system time to see if over 250ms passed. If so, we send another right click with Click, Right (don't use a send command here, it isn't really intended for this).
It looks like you're missing some curly braces around your if block; but I think you can implement the right double-click functionality with something as simple as,
RButton::
KeyWait RButton, T.25
numberOfClicks := errorLevel + 1
Send {Click Right %numberOfClicks%}
return
~RButton:: ;*When Right Mouse Button is Down, do the following.*
keywait RButton, T.25 ;*Wait (250 milliseconds) for it to be released.*
if errorlevel { ;*When it exceeds the said time*
keywait RButton ;*Wait for it to be released*
Send, {RButton Up} ;*Send Right Mouse Button up*
}
return
I want my code to be able to register if the mouse is clicked, and do something when that happens, but also to be able to register if the mouse is held down and not interrupt the mouse being held down if that is the case. For example,
If AutoCAD is open
If mbutton is clicked
click the escape key
If mbutton is held down
be able to use the mbutton held down as usual
End
I've tried a couple of different ways to do this but I don't have the knowledge to do this exactly. I've got the "If AutoCAD is open", and the "click the escape key" parts down, just not the "use the mbutton as normal if held down part"
Thanks for any help you can provide!
This was a bit of a tricky one. Change the #IfWinExist line accordingly. You can adjust the duration to be what you would consider "holding" MButton
SetTitleMatchMode, 2
#IfWinExist AutoCAD
~MButton::
duration := 100
start := A_TickCount
While(GetKeyState("MButton"))
{
if ((A_TickCount - start) > duration)
{
KeyWait, MButton
Send {MButton Up}
Return
}
}
Send, {Escape}
Return
#IfWinExist AutoCAD
If I understand you right, you are searching for the UP keyword:
The word UP may follow the name of a hotkey to cause the hotkey to
fire upon release of the key rather than when the key is pressed down.
(documentation)
#if autocad()
MButton Up::
send {escape}
return
#if
autocad() {
return true
}
I want to produce something like this :
1. When i press Esc 2 times (double) i want to produce my "made-up custom action"
2. When i press Esc 1 time i want to produce the original Escape
ok, here is the explanation of my question :
This code should apply as global, means when i start the script it will work on all windows
%ALAT1% is variable the Active Windows title , abbreviation "Anime Land Akui Transform" some kind of silly anime game
If i press Esc one time . it will "pause" the game, but when i press Esc 2 times, it will "exit" the game"
I want to do a custom action when i press Esc 2 times, but i also don't want the original Esc key function got override when i press 1 time.
Escape::
if (A_PriorHotkey = A_ThisHotKey and A_TimeSincePriorHotkey < 400)
WinActivate, %ALAT1%
IfWinActive, ahk_class TscShellContainerClass
{
Send {F5} ; F5 contains another action
}.
else
{
*Do original function of Escape i.e Send {Escape} ; Now this is the problem
}
return
after i try the code above : suppose i press "Escape" button it will loop the Escape as if i press Escape 2 times. So my real question is how to make "original 1 times press Esc key function" won't loop to "our custom 2 times press Esc key function" ?
Change the first line of your code to;
$Escape::
This will set it so that the hotkey is only triggered by real keystrokes not simulated ones.