如何在AutoHotKey中切换键盘映射 [英] how to toggle keyboard mapping in AutoHotKey

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

问题描述

我想将键盘的一部分映射为数字键盘:(我的笔记本电脑键盘没有数字键盘)

I would like to map part of my keyboard as a number pad:(my laptop keyboard has no number pad)

j->1
k->2
l->3
u->4
i->5
o->6

我想用一个快捷方式切换映射,比如说 Control + Alt + M , 我的代码在下面,但是,我不知道如何重置映射:

I would like to toggle the mapping with a short cut, let's say Control+Alt+M, my code is below, however, I don't know how to reset the mapping:

mode = 0

^!m::
  if (mode = 1)
  {
    mode = 0
    j->1
    k->2
    l->3
    u->4
    i->5
    o->6
  }
  else
  { 
    mode = 1
    u::u ;got error here: duplicate hotkey
  }
return

我在u::u处出现重复的热键错误,似乎AHK不允许在脚本中映射多个键. GetKeyState("NumLock", "P")不起作用,因为我没有 NumLock .

I got duplicate hotkey error with u::u, seems AHK does not allow mapping more than one key in a script. GetKeyState("NumLock", "P") does not work because I have no NumLock.

我可以用以下代码实现:

I am able to achieve with this code:

^!m::
Suspend
u::4
i::5
o::6
return

但这会切换整个脚本,这显然不好.因此,我希望有一个更好的解决方案.

But this would toggle entire script, which is apparently not good. So I would like a better solution than this.

推荐答案

如果运行AKH_L(例如AutoHotkey v1.1.10.01),则可以使用#IF语句来控制热键(就像您可以控制上的热键一样).带有#IfWinActive的应用程序级别).

If you run AKH_L (e.g. AutoHotkey v1.1.10.01), you can use the #IF statement to control the hotkeys (like you would control the hotkeys on an application level with #IfWinActive).

Mode := 0

^!m::
    mode:=!mode ;not! toggle
return

#If mode ; All hotkeys below this line will only work if mode is TRUE
    j::1
    k::2
    l::3
    u::4
    i::5
    o::6
#If

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆