Are dual key operations possible in AHK?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Are dual key operations possible in AHK?

06 Apr 2015, 19:29

I am open to suggestions but I can no longer have CapsLock, Insert, <ctrl> <alt> and <windows> continue to operate as single keys. <Shift> any of those keys would be best to use them. For example, someone should not enable capslock without pressing <shift> first.

Is this possible?
I wish I knew now half of what I thought I knew when I was a teenager.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Are dual key operations possible in AHK?

06 Apr 2015, 21:16

Yep

remaps Shift+Caps to Capslock and disables normal Capslock. Make sure to keep this order, I had problems when I reversed them

Code: Select all

$+Capslock::Capslock
Capslock::return
alternatively you can use this (sometimes the above was unreliable for me)

Code: Select all

$+CapsLock::
   SetCapslockState, % GetKeyState("Capslock", "T") ? "off" : "on"
return

Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Re: Are dual key operations possible in AHK?

06 Apr 2015, 21:34

Starting to love it.
Now for the numeric key pad. With NumLock off, can PgUp be reprogrammed to the colon (:) and the rest to other symbols?
I wish I knew now half of what I thought I knew when I was a teenager.
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Are dual key operations possible in AHK?

06 Apr 2015, 23:24

Emerogork wrote:Starting to love it.
Now for the numeric key pad. With NumLock off, can PgUp be reprogrammed to the colon (:) and the rest to other symbols?
try something like this:

Code: Select all

NumpadPgDn:::
it looks weird, but the syntax for remapping is original_key::replacement_key

http://ahkscript.org/docs/misc/Remap.htm
http://ahkscript.org/docs/KeyList.htm

Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Re: Are dual key operations possible in AHK?

11 Apr 2015, 15:11

I have this line that works:
$+capslock::capsLock
Capslock::send{ }

but I would prefer to have the right side shift instead if the left side.

RShift fails
>+ lets both shift buttons work.

My guesses yield error reports when I try to activate the script. Invalid HotKey



What code should I use?
I wish I knew now half of what I thought I knew when I was a teenager.
MindCaged
Posts: 19
Joined: 19 Jun 2014, 12:33

Re: Are dual key operations possible in AHK?

11 Apr 2015, 19:45

Hmm, I'm not sure if it's related, but I was trying to setup a hotkey the other day to only toggle capslock when I held both shift keys and then press capslock, but it didn't register, I'm guessing maybe a scancode conflict or something.

I did change it to RShift + Capslock and I haven't had any problems myself, as I currently have a >+CapsLock:: toggling my capslock state just fine.

I suppose you could try ~RShift & Capslock:: Instead, but it should essentially be the same thing.

Have you tried installing the keyboard hook and seeing what happens when you press the keys? I know some keyboards can do some weird things with keys.
Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Re: Are dual key operations possible in AHK?

11 Apr 2015, 20:18

~Rshift+Capslock and RShift&Capslock both produce "Invalid HotKey" errors.
>+capslock::capslock will allow both left and right shift with capslock
will change change capslock.

Can I presume that none of this coding is case sensitive?

You have it set up to require both left and tight shift?
Wow, really hate that key, no?
I wish I knew now half of what I thought I knew when I was a teenager.
MindCaged
Posts: 19
Joined: 19 Jun 2014, 12:33

Re: Are dual key operations possible in AHK?

11 Apr 2015, 22:21

No, I tried at first to do both right and left shift just to see if I could, It didnt work though since when I'm holding down both, then my keyboard doesn't register the capslock key at all. Then I thought I only really need the right shift to keep me from hitting it accidentally, so I just did that. Although I also have had for a while a script so it toggles on double-tap. And I actually have grown to somewhat love the capslock key as it's perfect for stuff in autohotkey, something easy to reach with a mostly useless function and I don't have to worry about conflicts with other stuff. Still, with the double tap code I will occasionally still accidentally trigger it, so I thought I'd try something different.

Anyway, I have a thought about your problem. Are you /sure/ that the /hotkey/ is being triggered by LeftShift+Capslock? And that it's not just the capslock function itself? Basically do you have another hotkey to block the CapsLock key like:

Code: Select all

CapsLock::return
That's something similar to what I have, although perhaps you might have to put a * in front like:

Code: Select all

*CapsLock::return
That's so that it'll also trigger on/block it while modifiers are held down like ctrl/alt/shift/win. Although mine works fine without it, though I use the SetCapsLockState function to lock my capslock state with the AlwaysOn/AlwaysOff argument so that I can only change it on purpose.
Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Re: Are dual key operations possible in AHK?

12 Apr 2015, 09:07

Now it is suggested to precede code with an *. I have seen the use of ~ also. Is there an
explanation of what these do? What others?

I did try to use "capslock::return" but found "capslock::send { }" to work there and
in other places.

The capslock key is the most aggravating key and I wonder why it has lasted so
long as it has. The second one is the INS key. I cannot fathom how so many of
my students don't understand what it does. It is as if those 5 other keys nearby
are never used.

I think I am spending just too much time trying to find an alternate way to have it work
and yet cannot think of a single time when I actually did want to use it.

I used to pull off the cap of the key off to avoid hitting it. Interestingly, I could use a pen
to reach down into the slot to activate the CapsLock. Similarly, I used to have a keyboard
with three more keys just above the "Print Screen" set. One was to shutdown the computer!
Another was sleep mode and I forget what the other offending key was. Imagine accidentally
turning off the computer as often as you accidentally hit CapsLock!
I wish I knew now half of what I thought I knew when I was a teenager.
MindCaged
Posts: 19
Joined: 19 Jun 2014, 12:33

Re: Are dual key operations possible in AHK?

12 Apr 2015, 10:09

I really understand. If you think those power keys up top are bad, on my old keyboard they were embedded right between the arrow keys and the home keys, so I would sometimes sleep the computer when I was reaching up from the arrow keys to the home keys. Unfortunately even with autohotkey you can't rebind them 99 percent of the time, as they completely bypass the keyboard handler and go straight to the OS, the only thing I could possibly think might work is if somebody wrote a custom keyboard driver and I'm not sure even that would work. Although I think you can disable them globally, although this also effects the button(s) on the computer case.

As for the capslock key, I have rarely used it, although I suppose in some instances it has been useful in the past. There are some programs and applications which require you to use uppercase characters a lot. I think I remember vaguely when I was learning some programming in high school they had us learn COBOL, if I'm remembering right every command needed to be in upper case.

I for one hate when keyboard manufacturers remove /any/ standard keys, at least now that I have autohotkey and can rebind most of of them. For example, a lot of logitech keyboards remove the AppsKey or move it so you have to hit a combination of keys, or change it into a Fn-key which can only modify certain keys. While I admit the built-in use of it is not often used, with Autohotkey it becomes super useful. Frankly, with autohotkey I love having /any/ extra physical keys because I can reprogram them. It's actually rather hard to find a keyboard nowadays with all the media keys, even supposed multimedia keyboards might be limited to say volume keys and maybe play/stop/next/prev, and many of the ones that /do/ have the other functions are not actually extra physical keys, but a combination with the Fn key. If I wanted to hit a key and F5 to play/pause, I would just setup that hotkey in AHK, not to mention I could rebind every other key as well. Say they change the Appskey into a Fn key, The Fn key will only modify whatever few keys they gave an extra function, with the AppsKey and Autohotkey however I could combine it with just about every key on the keyboard.

As for the explanation. Just like + ^ ! # mean Shift Ctrl Alt Windowskey, * means any modifier or combination of modifiers. Although if there's a more specific hotkey it takes priority. So +Capslock:: would take priority over *CapsLock::. As for ~ that prevents autohotkey from blocking the key's native function. By default any hotkey blocks itself from being sent on to the system so that the program isn't responding to both the native function /and/ the hotkey, ~ allows the key to work normally and if it matches the hotkey then it'll also trigger the code. This is good so you don't block say the shift key, like some games use the shift key by itself to trigger an action like firing a weapon.

*CapsLock::return should register any combination of modifiers(including no modifiers) plus CapsLock. return is just to immediately return without doing anything. You need to put some command after the hotkey for it to register as a single line hotkey. If you were just to put *CapsLock:: then it would register as a multi-line hotkey and start executing commands after that line until it encounters the end of the file or a return. The blocking of the key is handled automatically unless you were to put a ~ in front of it(Sometimes you don't want to block the key but you want to perform code when the key is pressed.). However since you're trying to block the key that's not what you want.

You can check http://ahkscript.org/docs/Hotkeys.htm for the documentation on * and ~ and the other modifiers.
Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Re: Are dual key operations possible in AHK?

12 Apr 2015, 10:35

Actually the original Caps Lock key was an effort to engage. You had top press the shift then hit capslock and it would hold the shift key down. When you pressed Shift, it would lift the carriage about 1/4" so that the impact of the keys would strike the platen at a different angle. (tmi?)

I wonder why they changed to to be such a flimsy engagement.
Thank you Steve Jobs (It was his design)
I wish I knew now half of what I thought I knew when I was a teenager.
MindCaged
Posts: 19
Joined: 19 Jun 2014, 12:33

Re: Are dual key operations possible in AHK?

12 Apr 2015, 10:46

Also makes you wonder with whomever came up with putting the power/sleep keys on the keyboard why they couldn't have made it so you had to hold down another key like say the shift key while doing so, that would've been so much better. I mean it can't possibly be that hard. Though perhaps not intuitive unless they print "Hold Shift" on the power keys as well.
Emerogork
Posts: 25
Joined: 06 Apr 2015, 19:20

Re: Are dual key operations possible in AHK?

13 Apr 2015, 19:39

I fixed that problem.
Used a pair of pliers and simply yanked them like impacted wisdom teeth.

When does one use the ~, *, $ or no special character at the beginning of a line of code?
I wish I knew now half of what I thought I knew when I was a teenager.
MindCaged
Posts: 19
Joined: 19 Jun 2014, 12:33

Re: Are dual key operations possible in AHK?

13 Apr 2015, 20:57

Well, I explained * and ~. I put a link in my post to the documentation. And they don't really go in front of a line of code, only in front of the name of a hotkey, there's a difference since code can be multiline and also doesn't even need a hotkey to function. You can use AHK script as a regular script file, if there are no hotkeys defined it'll exit when it reaches the end of the file or a return or ExitApp command or something. You can use this to run a bunch of commands like a complex batch file.

As for $, that makes it use the windows hook for the hotkey, which probably doesn't mean much to you but for practical purposes, if the hotkey is going to send itself, say you make a hotkey like a::Send Cat, it would be sending the letter a, which might result in an infinite loop as it would trigger itself depending on certain factors. So by making it $a::Send Cat it would prevent it from triggering on itself. There might be other applications where you might want it to use the hook as well, but that is the primary use of it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder and 243 guests