Matthew Gregoire
Matthew Gregoire

Reputation: 65

How do I change shortcut keys with autohotkey?

I use a Dvorak keyboard. Shortcuts like ctrl+x, ctrl+c, and ctrl+v are hard to use, so is there any way to remap them to ctrl+q, ctrl+j, and ctrl+k respectively, using AutoHotKey? Thanks!

Upvotes: 3

Views: 2088

Answers (3)

GG2
GG2

Reputation: 181

Dvorak puts w and v right next to each other. That makes it too easy to accidentally close windows while only wanting to paste. So, if you want to also disable the "original" shortcut keys, this appears to work:

HandleCtrlQOrX(key) {
    if (key = "x") {
        return
    }
    Send "^x"  ; Send ctrl+x only if ctrl+q was pressed
}
^q::HandleCtrlQOrX("q")
^x::HandleCtrlQOrX("x")

HandleCtrlJOrC(key) {
    if (key = "c") {
        return
    }
    Send "^c"  ; Send ctrl+c only if ctrl+j was pressed
}
^j::HandleCtrlJOrC("j")
^c::HandleCtrlJOrC("c")

HandleCtrlKOrV(key) {
    if (key = "v") {
        return
    }
    Send "^v"  ; Send ctrl+v only if ctrl+k was pressed
}
^k::HandleCtrlKOrV("k")
^v::HandleCtrlKOrV("v")

This can help with retraining the shortcuts.

For further example, I also created close_window.ahk along with the x/c/v reassignment:

HandleCtrlDOrW(key) {
    if (key = "w") {
        return
    }
    Send "^w"  ; Send ctrl+w only if ctrl+d was pressed
}
^d::HandleCtrlDOrW("d")
^w::HandleCtrlDOrW("w")

Change 'd' to whatever you want it to be, of course.

(I set these up using AutoHotkey v2.0. I haven't looked to see if any of the function syntax would be different for v1.x.)

Upvotes: 0

szczvr
szczvr

Reputation: 21

It is straightforward indeed, only to achieve the effect you want, you need to code it the opposite way:

^q::^x
^j::^c
^k::^v

It translates to <what-keys-you-press>::<what-is-sent-instead>. Just be aware you may create a conflict, if some application happens to have these shortcuts defined.

Upvotes: 2

Diamond
Diamond

Reputation: 11

Yes, this is pretty straight forward.

^x::^q
^c::^j
^v::^k

Note, this does not alter the behavior of the original shortcuts. To do that you would have to remap those as well. For more information, look at "remap keys or mouse buttons" in the help file. It also describes a method for remapping keys somewhat more directly from the registry.

Upvotes: 0

Related Questions