Before I ask my question let me say that this is a truly awesome piece of software; kudos and thanks to all involved.
This is my first time doing any sort of coding. I've spent the majority of my time these past two weeks trying to teach myself scripting (I'm very bad at it). I've managed to make some headway and get past previous problems, but after scouring the documentation and searching these forums for half a day I'm no closer to overcoming my latest hurdle(s).
So my first question is, is there a way to have an ahk script (continuously) intercept and interpret the keystrokes of another ahk script? (further explanation below)
My next question is, is there a way to send modifiers or additional keys along with a hotkey (without including them in a hotkey's definition)? (further explanation below)
For context, here are the relevant parts of my script:
Code:
; script.ahk
; this is part of my all-inclusive script that will run continuously from logon to logoff
; it runs dvorak.ahk (below) when scrolllock is toggled on
#usehook
~scrolllock::
getkeystate scroll,scrolllock,t
if scroll = d
run c:\documents and settings\admenstruator\desktop\temp backups\dvorak.ahk
setscrolllockstate on
return
Code:
; dvorak.ahk, run by the above script when scrolllock is on
; this is just a sample segment, for one key out of 33
; it exits when scrolllock is toggled off
#usehook
scrolllock::
setscrolllockstate off
exitapp
k::send t
^k::send ^t
!k::send !t
^!k::send ^!t
+k::send +t
^+k::send ^+t
!+k::send !+t
^!+k::send ^!+t
#k::send #t
; send "t" when "k" is pressed, "Ctrl + T" when "Ctrl + K" is pressed, etc.
; repeat ad nauseum
I suppose a bit of explanation is in order. I'm trying to have my computer run in Dvorak when scrolllock is on and Qwerty when it's off, which would make my roommates/other users of my computer very happy. Using Windows' built-in keyboard layout tools requires pressing wierd key combinations, there's no indicator light, and it only applies changes to the current window (or desktop). And if there's a program that can do something like this, I'd expect it to be AHK.
My scripts are currently bug free. However, I have the feeling I'm missing something by making 9 hotkeys each for 33 keys (but if I don't, "Alt + K" won't send "Alt + T," and so on). More importantly, it does not work in conjunction with the following piece of script:
Code:
; also part of script.ahk
; for starters, this makes the Dvorak keys CHTN (Qwerty IJKL) into arrow keys when capslock is on.
; (it does the same for several left-hand keys and the home, end, pgup, and pgdn keys)
; also, escape and capslock have been swapped (damn handy for Vim and everything else)
#usehook
setcapslockstate alwaysoff
hotkey t,off
hotkey ^t,off
hotkey +t,off
hotkey ^+t,off
t::send {down}
^t::send ^{down}
+t::send +{down}
^+t::send ^+{down}
*capslock::
hotkey t,on
hotkey ^t,on
hotkey +t,on
hotkey ^+t,on
keywait capslock
if a_thishotkey = *capslock
send {esc}
hotkey t,off
hotkey ^t,off
hotkey +t,off
hotkey ^+t,off
return
esc::
getkeystate lock,capslock,t
if lock = u
setcapslockstate alwayson
if lock = d
setcapslockstate alwaysoff
return
If I did the preceding section any other way (e.g. capslock & t::send {down} ) it would turn the capslock on whenever other keys were pressed, hence that style of code. It works wondrously on its own, but when I switch on Dvorak with the previous scripts, it doesn't capture the right keystrokes, obviously.
Now, I know there are ways of working around these problems (such as appending a remapped version of the prior script to dvorak.ahk) but before I actually make key bindings for everything, I have to ask if there are more efficient methods of doing so.
After looking around the documentation, my guess is "no" to both of my prior questions (if so may they be added to the wish list?). In terms of my current project it's possible, if not efficient, to work around them, but of all the useful functions AHK ought to be able to do, I'd think this sort of keystroke manipulation would be top priority.
Apologies for such a long post, and I certainly don't mean to come off sounding disappointed with the program. Thanks in advance for all your help.
I will conquer you yet, Capslock! Next up, 101 uses for the accent/tilde key.