do something if i press any key except one?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
adrian88888888
Posts: 84
Joined: 13 Mar 2020, 22:51

do something if i press any key except one?

16 Apr 2021, 15:56

What I have:

In my script if I turn on caps lock all the keys of the keyboard does another thing instead of typing keys, for example:

Code: Select all

#If CapsLockIsPressed()
1::GoToDesktop(1)
2::GoToDesktop(2)
3::GoToDesktop(3)
4::GoToDesktop(4)

p::OpenControlPanel()
...
#If

What im trying to do:

With caps lock on I want to press "n" and enter in some kind of "new mode"
Then if I press "f" I want to make a new folder, or if I press "t" a new tab, and so on
So I would press "nf" do do a new folder, and "nt" to do a new tab

So:

Code: Select all

SetCapsLockState, on
global new_mode := false

#If CapsLockIsPressed()
n::
new_mode := true
return
#If

#If new_mode
f::CreateNewFolder()
t::OpenNewTab()
any_other_key_that_is not_f_or_n::new_mode := false ; <=== how I archive this?
#If
The problem:

But if I press any other key that is not "f" or "t" I want to exit the "new mode"
For example if I do "nz" I want it to exit the "new mode"
How I do that?

Thanks!
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: do something if i press any key except one?

16 Apr 2021, 16:28

Code: Select all

#If GetKeyState("CapsLock", "T")
n::
Input, key, L1
Switch key {
 Case "f": Send 1
 Case "t": Send 2
}
Return
#If
adrian88888888
Posts: 84
Joined: 13 Mar 2020, 22:51

Re: do something if i press any key except one?

16 Apr 2021, 16:34

mikeyww wrote:
16 Apr 2021, 16:28

Code: Select all

#If GetKeyState("CapsLock", "T")
n::
Input, key, L1
Switch key {
 Case "f": Send 1
 Case "t": Send 2
}
Return
#If
That's really smart!, thanks!
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: do something if i press any key except one?

16 Apr 2021, 19:00

You are welcome. Another way is that you could set a timer for your "new mode", and have the timer expire (and reset the mode) after a few hundred milliseconds.

Code: Select all

#If GetKeyState("CapsLock", "T")
n::
on := True
SoundBeep, 1500
SetTimer, Off, -300
Return
Off:
on := False
SoundBeep, 1000
Return
#If on
f::Send 1
t::Send 2
#If

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CrowexBR and 269 guests