Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Fn key on apple wireless keyboard



  • Please log in to reply
2 replies to this topic
GloomyMoonie
  • Members
  • 3 posts
  • Last active: Feb 25 2014 11:53 PM
  • Joined: 20 Jun 2012
Hello AHK community, I was wondering if you could help me get the fn key to work.
Using https://ahknet.autoh.../Veil/fnkey.htm FnMapper.ahk to be exact, I've got both fn and eject keys recognized and working.
The problem is that I want to:
swap fn with ctrl
swap eject with del (since I use shift+del a lot)
get the media keys (F's) to work

I was trying to change this code (full version at the bottom, credits it the code) from winamp to wmplayer_app (or something like that) but then I tried F7::Media_Prev for the sake of seeing if it works, so it did, and now I want to make the hotkey fn+f7..9 to work as Media_Prev, Media_Play_Pause, Media_Next. from http://goo.gl/LcY64

hotkeyF7() {
	global fnPressed
	if(fnPressed = 1) {
		IfWinNotExist ahk_class Winamp v1.x
  	Return
		ControlSend, ahk_parent, z  ; Previous
	} else {
		Send {F7}
	}
}
Return


CAN ANYONE PLEASE HELP? I'm so frustrated..

(had to download some missing dll's without which the volume hotkeys didn't work)
;
; AutoHotkey Version: 1.x
; Language.........: English
; Platform.........: NT/XP/Vista
; Author...........: Veil, Leon
; Full guide.......: http://brrp.mine.nu/fnkey/
;
; Script Function..: Remapping the Fn key
;                    Modified specifically for the Apple Wireless Keyboard
;
; 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")
   
  ; 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) {
  	; Fn is pressed
		fnPressed := 1
  } else {
    ; Fn is released
		fnPressed := 0
  }
  
  if (EjectValue = 8) {
  	; Eject is pressed
  	; Set timeout of 1 second to prevent accidental keypresses
		SetTimer, ejectDrive, 1000
  } else {
  	; If the Eject button is let go within the second it will disable the timer and skip the ejectDrive function
		SetTimer, ejectDrive, Off
  }
  
} ; 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


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 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 < 1000 ; Adjust this time if needed.
	    Drive, Eject,, 1
	Return
Return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Fn modifier: Various
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;
; Fn + Backspace = Delete
;
$Backspace::hotkeyBS()

hotkeyBS()
{
	global fnPressed
	if (fnPressed = 1) {
		Send {Delete}
	} else {
		Send {Backspace}
	}
}
Return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Fn modifier: Audio hotkeys, specified for Winamp
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;
; Winamp: Previous
;
$F7::hotkeyF7()

hotkeyF7() {
	global fnPressed
	if(fnPressed = 1) {
		IfWinNotExist ahk_class Winamp v1.x
  	Return
		ControlSend, ahk_parent, z  ; Previous
	} else {
		Send {F7}
	}
}
Return

;
; Winamp: Pause/Unpause
;
$F8::hotkeyF8()

hotkeyF8() {
	global fnPressed
	if (fnPressed = 1) {
		IfWinNotExist ahk_class Winamp v1.x
  	Return
		ControlSend, ahk_parent, c ; Pause/Unpause
	} else {
		Send {F8}
	}
}
Return

;
; Winamp: Next
;
$F9::hotkeyF9()

hotkeyF9()
{
	global fnPressed
	if (fnPressed = 1) {
		IfWinNotExist ahk_class Winamp v1.x
  	Return
		ControlSend, ahk_parent, b ; Next
	} else {
		Send {F9}
	}
}
Return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Fn modifier: Audio hotkeys, system volume
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;
i


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Fn modifier: Arrow keys
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

GetKeyState, ShiftState, Shift, P
			

;
; Page Up
;
$UP::hotkeyPgUp()

hotkeyPgUp() {
	global fnPressed
	if (fnPressed = 1) {
		if (ShiftState = D) {
			Send {Shift}{PgUp}
		} else {
			Send {PgUp}
		}
	} else {
		Send {UP}
	}
}
Return

;
; Page Down
;
$Down::hotkeyPgDn()

hotkeyPgDn() {
	global fnPressed
	if (fnPressed = 1) {
		Send {PgDn}
	} else {
		Send {Down}
	}
}
Return

;
; Home
;
$Left::hotkeyHome()

hotkeyHome() {
	global fnPressed
	if (fnPressed = 1) {
		Send {Home}
	} else {
		Send {Left}
	}
}
Return

;
; End
;
$Right::hotkeyEnd()

hotkeyEnd() {
	global fnPressed
	if (fnPressed = 1) {
		Send {End}
	} else {
		Send {Right}
	}
}
Return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Regular hotkeys: Mac functionalities
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;#p::^p
;#z::^z
;#x::^x
;#c::^c
;#v::^v
;#d::SendInput, ^d
;#a::^a
;#n::^n
;#t::^t
;#s::^s
;#f::SendInput, ^f
;#l::^l
;#w::^w
;#r::F5
;#q::!F4
;#]::SendInput {Tab}
;#[::SendInput +{Tab}
;#UP::PgUp
;#Down::PgDn
;#Left::Home
;#Right::End


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Regular hotkeys: Other hotkeys
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;#F11::PrintScreen
;VKE2SC056::Send {ASC 0128} ; euro sign on paragraph key
;Shift & VKE2SC056::SendInput ~
;LWin & Tab::AltTab

;RAlt::Send +{F10}



;#Include SpecialCharacters.ahk


Billy TK
  • Members
  • 2 posts
  • Last active: Aug 03 2016 01:28 PM
  • Joined: 24 Nov 2012
✓  Best Answer

Maybe my script helps for you.

 

http://www.autohotke...ject-to-delete/

or

https://gist.github....plewkhelper-ahk

 

It make all you need and works witout any addition DLL. You must use the Microsoft keyboard driver (not Apple driver) 



GloomyMoonie
  • Members
  • 3 posts
  • Last active: Feb 25 2014 11:53 PM
  • Joined: 20 Jun 2012

Oh my god, thank you so much! I should say that this inspires me quite a bunch. 

 

Btw, is there any way to make the ctrl+alt+del work?

Also, which driver exactly (they have like 20 on their site)?