Eject and Fn keys on Apple wired aluminum keyboard

Post your working scripts, libraries and tools
k76
Posts: 2
Joined: 30 Jun 2020, 05:09

Eject and Fn keys on Apple wired aluminum keyboard

30 Jun 2020, 05:37

EJECT key: I had trouble finding a newbie friendly solution, so after spending a day searching the forum and pasting this together I wanted to share, maybe it helps some other beginner. Search for the AHKHID script and put it in the same folder with this, I just call it EjectTest.ahk

Code: Select all

#Include AHKHID.ahk
#Persistent
;Create GUI to receive messages
Gui +LastFound
hGui := WinExist()

; Register Mac kbd with RIDEV_INPUTSINK, data is received in the background
r := AHKHID_Register(12, 1, hGui, RIDEV_INPUTSINK)
WM_INPUT := 0xFF
;Intercept WM_INPUT messages
OnMessage(WM_INPUT, "InputMsg")
Return

InputMsg(wParam, lParam) {
  Local devh, iKey
  ;Get handle of device
  devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
  ;Get device name
  devname := AHKHID_GetDevName(devh, True)
    ; Uncomment next 2 lines to see all HID input when starting to find the one you want
    ; You can ctrl-c copy the HID device id from the msgbox window
    ;iKey := AHKHID_GetInputData(lParam, uData)
    ;MsgBox devname %devname% uData %iKey%
  Critical on  
  If (devname = "\\?\HID#VID_05AC&PID_0220&MI_01#8&2d0a62ca&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}")
  {
    ; Insert your actions here, MsgBox can be deleted
    MsgBox EJECT pressed on Apple wired aluminum keyboard
  }
  Critical off
  Return
}
Included devname is what it is on my Windows 10 box, it might be different on yours. Use AHKHID examples 1 and 2 to try to find out the devname. Strangely mine was different that what the examples showed! Here's the data:
AHKHID example showed this:
\\?\HID#VID_05AC&PID_0220&MI_00#8&49fb501&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
VendorID: 1452
ProductID: 544
Version#: 103
UsagePage/Usage: 12/1
Data: 0008 key down, 0000 key up
Byte: 0 8 0 0 0 0 0 0
Byte0-^ ^-Byte7
Hex Data: 0008

But popup from EjectTest showed this, which works:
---------------------------
EjectTest.ahk
---------------------------
Devname is \\?\HID#VID_05AC&PID_0220&MI_01#8&2d0a62ca&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
---------------------------
OK
---------------------------

FN key: It's really impossible without an external DLL? Would someone have saved the source for Micha's DLLCall, if it ever was available?
Also found this, anyone ever took a look? Interception
k76
Posts: 2
Joined: 30 Jun 2020, 05:09

Re: Eject and Fn keys on Apple wired aluminum keyboard

01 Jul 2020, 06:13

Seems it makes a good RDP keyboard since the Eject button is not sent to remote in full screen mode, it being a HID device input. But I didn't have success with plain

Code: Select all

Send {LWin down}{LCtrl down}{Left down}{LWin up}{LCtrl up}{Left up}
nothing would happen.

Then found out that it needs some delays, and detach from current RDP session is guaranteed every time Eject is pressed:

Code: Select all

    Send {Ctrl down}{Alt down}
    Sleep, 100
    Send {Home down}
    Sleep, 200
    Send {Home up}
    Sleep, 100
    Send {Alt up}{Ctrl up}
The delays are not optimized for shortness, just trying to mimic human input.

Map F13 and F14 to scroll virtual desktops left and right and it's very pleasurable to use:

Code: Select all

F13::Send ^#{Left}
F14::Send ^#{Right}

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], leosouza85, Tom Harding and 26 guests