Autohotkey 布局独立 "Input"。等待任意键。 "Input" 备选方案

Autohotkey layout independent "Input". Wait for any key. "Input" alternatives

这是我的部分脚本:

~LWin Up::
  Input, key, L1
  if (key = "n") {
    Run, Notepad.exe
  }
  else if (key = "s") {
    Run, cmd.exe
  }      
return

释放LWin后等待另一个键被按下,然后运行与该键对应的应用程序。 Тhe 问题是,如果我切换到俄语布局 's' 变成 'ы' 并且脚本将无法运行。

如何使其布局独立?复制“ы”的代码不是选项。

解决方案可能是这样的:

#n::
#s::
  stringsplit, splitted_, A_ThisHotkey
  key := splitted_2
  if (key = "n") {
    Run, Notepad.exe
  }
  else if (key = "s") {
    Run, cmd.exe
  }
  Send {LWin up} ; release LWin
return

~LWin Up::
  stringsplit, splitted_, A_PriorHotkey
  if (splitted_1 = "#") { ; if win+key combo has just been released
    return                ; no need to keep LWin down
  }
  Send {LWin down}        ; else keep it down
return

我已经试过了,但它不能正常工作。有时它不会释放 LWin,有时它不会一直按下。而且这种方法还有其他缺点,所以我不想使用它。

您的第一个脚本似乎可以与最新的 Unicode 版本的 AutoHotkey 一起正常工作。获取最新版本@ ahkscript.org

在下面的代码中添加了对“ы”的检查:

~LWin Up::
  Input, key, L1
  if (key = "n" or key = "ы") {
    Run, Notepad.exe
  }
  else if (key = "s") {
    Run, cmd.exe
  }      
return

确保使用 UTF-8 脚本(不是没有 BOM 的 UTF-8)进行编码

编辑:

好的,我想我找到了一个答案,它不需要您添加“ы”而是依赖于键盘产生的 SC 代码,这意味着它与布局无关。

Relevant info from Input command from the Docs:

E [v1.1.20+]: Handle single-character end keys by character code instead of by keycode. This provides more consistent results if the active window's keyboard layout is different to the script's keyboard layout. It also prevents key combinations which don't actually produce the given end characters from ending input; for example, if @ is an end key, on the US layout Shift+2 will trigger it but Ctrl+Shift+2 will not (if the E option is used). If the C option is also used, the end character is case-sensitive.

EndKeys A list of zero or more keys, any one of which terminates the Input when pressed (the EndKey itself is not written to OutputVar). When an Input is terminated this way, ErrorLevel is set to the word EndKey followed by a colon and the name of the EndKey. Examples: EndKey:., EndKey:Escape.

The EndKey list uses a format similar to the Send command. For example, specifying {Enter}.{Esc} would cause either ENTER, period (.), or ESCAPE to terminate the Input. To use the braces themselves as end keys, specify {{} and/or {}}.

To use Control, Alt, or Shift as end-keys, specify the left and/or right version of the key, not the neutral version. For example, specify {LControl}{RControl} rather than {Control}.

Although modified keys such as Control-C (^c) are not supported, certain characters that require the shift key to be held down -- namely punctuation marks such as ?!:@&{} -- are supported in v1.0.14+. Other characters are supported with the E option described above, in v1.1.20+.

An explicit virtual key code such as {vkFF} may also be specified. This is useful in the rare case where a key has no name and produces no visible character when pressed. Its virtual key code can be determined by following the steps at the bottom fo the key list page.

~LWin Up::
  Input, key, L1 E, {SC031}.{SC01F} ; {n}.{s}
  if (Errorlevel = "EndKey:SC031") {
    Run, Notepad.exe
  }
  If (Errorlevel = "EndKey:SC01f") {
    Run, cmd.exe
  }
return

此外,我无法重现按住 Windows 键的问题?