-
Notifications
You must be signed in to change notification settings - Fork 5
/
FnMapper.ahk
156 lines (129 loc) · 4.93 KB
/
FnMapper.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Unofficial Apple Wireless Keyboard Support ;;
;; http://code.google.com/p/uawks/ ;;
;; ;;
;; Version 2008.09.17 ;;
;; ;;
;; by Brian Jorgensen ;;
;; (based on work by Leon, Veil and Micha) ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The code below is slightly modified from the original
;; version by Veil, but I've made an effort to keep it
;; mostly intact. Thanks Veil! --BGJ
; AutoHotkey Version: 1.x
; Language.........: English
; Platform.........: NT/XP/Vista
; Authors..........: Veil, Leon
; Full guide.......: http://brrp.mine.nu/fnkey/
;
; Script Function..: Remapping the Fn key
;
; Based on.........: DLLCall: Support for Human Interface devices
; By...............: Micha
; URL..............: http://www.autohotkey.com/forum/viewtopic.php?t=6367
;
; Use..............: Spread the word! Just be sure to credit the writer of the dll
; file and the original config, and the authors of this file.
SendMode Input
; Set screen title, to set the HWND
Gui, Show, x0 y0 h0 w0, FnMapper
; Variable for the modifier key
FnKeyPressed := false
; Set the homepath to the relevant dll file
HomePath=AutohotkeyRemoteControl.dll
; Load the dll
hModule := DllCall("LoadLibrary", "str", HomePath)
; On specific message from the dll, goto this function
OnMessage(0x00FF, "InputMsg")
; Register at the dll in order to receive events
EditUsage := 1
EditUsagePage := 12
HWND := WinExist("FnMapper")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
WinHide, FnMapper
; This function is called, when a WM_INPUT-msg from a device is received
InputMsg(wParam, lParam, msg, hwnd)
{
DeviceNr = -1
nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTDataType", UINT, wParam, UINT, lParam, "INT *", DeviceNr, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == 0xFFFFFFFF)
{
MsgBox GetWM_INPUTHIDData fehlgeschlagen. Errorcode: %errorlevel%
goto cleanup
}
;Tooltip, %DeviceNr%
ifequal, nRC, 2
{
ProcessHIDData(wParam, lParam)
}
else
{
MsgBox, Error - no HID data
}
}
Return
ProcessHIDData(wParam, lParam)
{
; Make sure this variable retains its value outside this function
global FnKeyPressed
DataSize = 5000
VarSetCapacity(RawData, %DataSize%, 0)
RawData = 1
nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDData", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")
; Get the ID of the device
; Use the line below to check where an event was sent from,
; when using this code for a new HID device DeviceNumber :=
; DllCall("AutohotkeyRemoteControl\ GetNumberFromHandle",
; UINT, nHandle, "Cdecl UInt")
;FirstValue := NumGet(RawData, 0,"UChar") ; something to do
; with the bits, not really relevant here
KeyStatus := NumGet(RawData, 1, "UChar")
;MsgBox, Keystatus: %KeyStatus%
; Filter the correct bit, so that it corresponds to the key in question
; Add another Transform for a new key
; Filter bit 5 (Fn key)
Transform, FnValue, BitAnd, 16, KeyStatus
; Filter bit 4 (Eject key)
Transform, EjectValue, BitAnd, 8, KeyStatus
if (FnValue = 16) {
; SoundBeep
; Fn is pressed
FnKeyPressed := true
} else {
; Fn is released
FnKeyPressed := false
}
if (EjectValue = 8) {
; Eject is pressed
; Set timeout of 1 second to prevent accidental keypresses
; SetTimer, ejectDrive, 1000
;SoundBeep
;Send {Ctrl down}{Shift down}{Shift up}{Ctrl up}
;GetKeyState, state, Alt
;if state = D
; Send {Alt down}{Insert down}{Insert up}{Alt up}
Send {Insert down}
} else {
; If the Eject button is let go within the second it will
; disable the timer and skip the ejectDrive function
SetTimer, ejectDrive, Off
Send {Insert up}
}
} ; END: ProcessHIDData
; If there was an error retrieving the HID data, cleanup
cleanup:
DllCall("FreeLibrary", "UInt", hModule)
ExitApp
; Eject with a delay, Apple style
ejectDrive:
;startTime := A_TickCount
;Drive, Eject
; If the command completed quickly, the tray was probably already ejected.
; In that case, retract it:
;if A_TickCount - startTime < EjectDelayTime ; Adjust this time if needed.
; Drive, Eject,, 1
;Return
SoundBeep
Return