kyvaith wrote:
Ok it works
Good news! This is with the Apple Wireless Keyboard.ahk right?
kyvaith wrote:
Now, what could I do to remap fn to control and ejc to del? I need only this function - no winamp controls, no real ejc function. Could you help me?
I stripped down the file to just the things you need. Copy the code below, and save it to a file. Make sure to place the file in the same directory as the DLL. Close all other scripts that are running, and then run this one.
Code:
;
; 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.
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;#NoTrayIcon
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; DLL registration and readout of keys
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Set screen title, to set the HWND
Gui, Show, x0 y0 h0 w0, FnMapper
; Variable for the modifier key, define it here, just to be sure
fnPressed := 0
; 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 fnPressed
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) {
Send, {Ctrl down}
} else {
Send, {Ctrl up}
}
if (EjectValue = 8) {
Send, {Delete}
}
} ; END: ProcessHIDData
; If there was an error retrieving the HID data, cleanup
cleanup:
DllCall("FreeLibrary", "UInt", hModule) ; It is best to unload the DLL after using it (or before the script exits).
ExitApp
So run this, and see if it works. The parts that are relevant for you are:
Code:
if (FnValue = 16) {
Send, {Ctrl down}
} else {
Send, {Ctrl up}
}
if (EjectValue = 8) {
Send, {Delete}
}