本文介绍了AutoHotKey可以切换键盘映射吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图在AutoHotKey中编写一个简单的脚本,该脚本将使用NumLock(已将其映射到注册表中的capslock)作为将我的方向键转换为numpad nab键的切换.我的脚本如下:

So I'm trying to write a simple script in AutoHotKey that will use NumLock (which I have mapped to the capslock in my registry) as a toggle to turn my directional keys into the numpad nab keys. My script is as follows:

GetKeyState, state, NumLock, T
if state = D
{
    Up::Numpad8
    Down::Numpad2
    Left::Numpad4
    Right::Numpad6
    Enter::Numpad5
}
if state = U
{
    $Up::Up
    $Down::Down
    $Left::Left
    $Right::Right
    $Enter::Enter
}
Return

但是,我收到一条错误消息,说在第15行中重复执行Up.如何告诉AutoHotKey将我的密钥返回其原始密钥名称?我尝试将"else"部分保留为空白,而不是"if state = U"部分,但随后的键在再次切换时仍保持其更改后的状态.我确定我缺少一些简单的东西.

However, I get an error saying Up is repeated in line 15. How do I tell AutoHotKey to return my keys to their original key designation? I tried leaving an "else" section blank as opposed to the "if state = U" section, but then the keys remain in their altered state when toggling again. I'm sure there is something simple I am missing.

推荐答案

这是使用#If上下文.

这样做的好处是,您不必具有If语句即可将Else语句中的键重新映射回自身.如果条件不成立,密钥将保留其正常功能.

The advantage of this is that you will not have to have If statements to remap a key back to itself in the Else statement. The key will retain its normal functionality if the condition is not true.

#If GetKeyState("NumLock", "P")
    Up::Numpad8
    Down::Numpad2
    Left::Numpad4
    Right::Numpad6
    Enter::Numpad5
#If

这篇关于AutoHotKey可以切换键盘映射吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:37