root/windows/neo-vars/src/source/keyboardleds.ahk @ 1917

Revision 1917, 4.4 KB (checked in by mösi, 4 years ago)

Jetzt mal eine Variante der LED-Umschaltung, die auch mit der Lang-ſ-Tastatur richtig laufen sollte.

RevLine 
[1917]1UpdateOldLEDS() {
2  global
3  SwitchIsOn := 1
4  SwitchIsOff := 0
5  Num := SwitchIs%SavedScrollLockState% + 2*SwitchIs%SavedNumLockState% + 4*SwitchIs%SavedCapsLockState%
6  KeyboardLED(Num,"switch")
7}
8
9UpdateNEOLEDS() {
10  global
11  SwitchIsOn := 1
12  SwitchIsOff := 0
13  Num := SwitchIs%NEOScrollLockLEDState% + 2*SwitchIs%NEONumLockLEDState% + 4*SwitchIs%NEOCapsLockLEDState%
14  KeyboardLED(Num,"switch")
15}
16
17
[1186]18;ScrollLock=1, NumLock=2, CapsLock=4, bzw. eine beliebige Summe dieser Werte
19KeyboardLED(LEDvalue, Cmd){ ; LEDvalue: ScrollLock=1, NumLock=2, CapsLock=4 ; Cmd = on/off/switch
20  Static h_device
21  If ! h_device ; initialise
22  {
23    device=\Device\KeyBoardClass0
24    SetUnicodeStrLED(fn,device)
25    h_device:=NtCreateFileLED(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
26  }
27  VarSetCapacity(output_actual,4,0)
28  input_size=4
29  VarSetCapacity(input,input_size,0)
30  If Cmd=switch ;switches every LED according to LEDvalue
31   KeyLED:=LEDvalue
32  If Cmd=on ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
33   KeyLED:=LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
34  If Cmd=off ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
35    {
36    LEDvalue:=LEDvalue ^ 7
37    KeyLED:=LEDvalue & (GetKeyState("ScrollLock","T") + 2*GetKeyState("NumLock","T") + 4*GetKeyState("CapsLock","T"))
38    }
39  ; EncodeIntegerLED(KeyLED,1,&input,2) ;input bit pattern (KeyLED): bit 0 = scrolllock ;bit 1 = numlock ;bit 2 = capslock
40  input:=Chr(1) Chr(1) Chr(KeyLED)
41  input:=Chr(1)
42  input=
43  success:=DllCall("DeviceIoControl"
44    , "uint", h_device
45    , "uint", CTL_CODE_LED( 0x0000000b     ; FILE_DEVICE_KEYBOARD
46              , 2
47              , 0             ; METHOD_BUFFERED
48              , 0  )          ; FILE_ANY_ACCESS
49    , "uint", &input
50    , "uint", input_size
51    , "uint", 0
52    , "uint", 0
53    , "uint", &output_actual
54    , "uint", 0 )
55}
56
57CTL_CODE_LED(p_device_type,p_function,p_method,p_access ){
58  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
59}
60
61NtCreateFileLED(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs){
62  VarSetCapacity(fh,4,0)
63  VarSetCapacity(objattrib,24,0)
64  VarSetCapacity(io,8,0)
65  VarSetCapacity(pus,8)
66  uslen:=DllCall("lstrlenW","str",wfilename)*2
67  InsertIntegerLED(uslen,pus,0,2)
68  InsertIntegerLED(uslen,pus,2,2)
69  InsertIntegerLED(&wfilename,pus,4)
70  InsertIntegerLED(24,objattrib,0)
71  InsertIntegerLED(&pus,objattrib,8)
72  status:=DllCall("ntdll\ZwCreateFile","str",fh,"UInt",desiredaccess,"str",objattrib,"str",io,"UInt",0,"UInt",fattribs
73                  ,"UInt",sharemode,"UInt",createdist,"UInt",flags,"UInt",0,"UInt",0, "UInt")
74  return ExtractIntegerLED(fh)
75}
76
77SetUnicodeStrLED(ByRef out, str_){
78  VarSetCapacity(st1, 8, 0)
79  InsertIntegerLED(0x530025, st1)
80  VarSetCapacity(out, (StrLen(str_)+1)*2, 0)
81  DllCall("wsprintfW", "str", out, "str", st1, "str", str_, "Cdecl UInt")
82}
83
84ExtractIntegerLED(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4){
85; pSource is a string (buffer) whose memory area contains a raw/binary integer at pOffset.
86; The caller should pass true for pSigned to interpret the result as signed vs. unsigned.
87; pSize is the size of PSource's integer in bytes (e.g. 4 bytes for a DWORD or Int).
88; pSource must be ByRef to avoid corruption during the formal-to-actual copying process
89; (since pSource might contain valid data beyond its first binary zero).
90  Loop %pSize%  ; Build the integer by adding up its bytes.
91    result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
92  if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
93    return result  ; Signed vs. unsigned doesn't matter in these cases.
94  ; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
95  return -(0xFFFFFFFF - result + 1)
96}
97
98InsertIntegerLED(pInteger, ByRef pDest, pOffset = 0, pSize = 4){
99; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
100; only pSize number of bytes starting at pOffset are altered in it.
101  Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
102    DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
103}
104
Note: See TracBrowser for help on using the browser.