AHK:使用Numlock On重新映射数字小键盘,因此它的行为类似于Numlock Off的数字小键盘

时间:2015-12-29 05:08:51

标签: autohotkey

我想用Numlock On重新映射数字小键盘,就像Numlock Off的数字小键盘一样,包括能够按住Shift / Ctrl来扩展选择。

我遇到的问题如下

Numpad8::Up

按shift + numpad8时没有正确的行为,光标向上移动,但没有选择文本。以下内容也不起作用(与Numpad :: 8相同)。

+Numpad8::Up
+Numpad8::+Up

如果我重新映射一个普通键,按下shift时选择行为是正确的:

w::Up

任何提示?

我这样做的原因是让CoolerMaster QuickFire TK's数字小键盘表现得像它有一个标准的数字小键盘布局(我也发生了一些注册表键盘重映射,这就是为什么我想要导航行为与Numlock On)。

2 个答案:

答案 0 :(得分:1)

这是可能的,但与正常的重新映射相比,它是屁股的痛苦。

以下是Numpad8键的正常行为:

  

使用numpad:
  num8:up
  shift + num8:mark up

     

关闭小键盘:
  num8:8
  移位+ num8:最高

所以,如果你想扭转这一点,我们想要的是:

  

使用numpad:
  num8:8
  shift + num8:up

     

关闭小键盘:
  num8:up
  shift + num8:mark up

这是如何实现的:

*NumpadUp:: 
    If GetKeyState("NumLock", "T")
        SendInput, {Shift Down}{Up}
    Else If GetKeyState("Shift")
        SendInput, {Shift Up}{NumpadUp}
    Else
        SendInput, {Shift Up}{Numpad8}
Return


*Numpad8:: 
    If GetKeyState("Shift")
        SendInput, {Shift Down}{NumpadUp}
    Else
        SendInput, {NumpadUp}
Return

现在你只需要为你要反转的其他小键盘做同样的事情。

答案 1 :(得分:1)

这是一种不同的方法,它使用一点点黑客来使它看起来像按下numlock键时Numpad切换。但它确保numlock实际上总是关闭,只有numlock灯被更改。

SetNumLockState, Off
fakeNumlockOn := False
Return

NumLock::
    SetNumLockState, Off
    fakeNumlockOn := !fakeNumlockOn
    SetNumLockLEDs(fakeNumlockOn ? "on" : "off")
    Sleep, 100
    SetNumLockLEDs(fakeNumlockOn ? "on" : "off")
Return

SetNumLockLEDs(state) {
    Loop, 11
        KeyboardLED(2,state,A_Index-1)
}



/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/
KeyboardLED(LEDvalue, Cmd, Kbd=0) {
    SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
    h_device := NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
    If (Cmd = "switch")  ;switches every LED according to LEDvalue
        KeyLED:= LEDvalue
    If (Cmd = "on")  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
        KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    If (Cmd = "off") { ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
        LEDvalue := LEDvalue ^ 7
        KeyLED := LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
    success := DllCall( "DeviceIoControl" ,  "ptr", h_device , "uint", CTL_CODE( 0x0000000b , 2 , 0 , 0  ) , "int*", KeyLED << 16 , "uint", 4 ,  "ptr", 0 , "uint", 0 ,  "ptr*", output_actual ,  "ptr", 0 )
    NtCloseFile(h_device)
    return success
}
CTL_CODE( p_device_type, p_function, p_method, p_access ) {
    return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}
NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs) {
    VarSetCapacity(objattrib,6*A_PtrSize,0)
    VarSetCapacity(io,2*A_PtrSize,0)
    VarSetCapacity(pus,2*A_PtrSize)
    DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
    NumPut(6*A_PtrSize,objattrib,0)
    NumPut(&pus,objattrib,2*A_PtrSize)
    status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
    return % fh
}
NtCloseFile(handle) {
    return DllCall("ntdll\ZwClose","ptr",handle)
}
SetUnicodeStr(ByRef out, str_) {
    VarSetCapacity(out,2*StrPut(str_,"utf-16"))
    StrPut(str_,&out,"utf-16")
}