How to control special programmable buttons from AHKHID, not from Oscar macro Editor?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
csharperHH
Posts: 9
Joined: 20 Nov 2022, 19:07

How to control special programmable buttons from AHKHID, not from Oscar macro Editor?

Post by csharperHH » 28 Nov 2022, 02:40

I have an A4Tech X7-G800V programmable keyboard. I want to control special keys (g1-g16) from AHK using the built-in macro editor at a minimum. In this keyboard macro editor is called Oscar.
image.png
image.png (35.48 KiB) Viewed 293 times
How can I do it?

Found a complicated way using AHKHID.
Via the example script_1.apk from here https://www.autohotkey.com/board/topic/38015-ahkhid-an-ahk-implementation-of-the-hid-functions / I get my keyboard code (there are 2 of them in the list).
image.png
image.png (35.48 KiB) Viewed 293 times
I insert my values

Code: Select all

ProdName = \\?\HID#VID_04D9&PID_FC41&MI_01#9&406d4c2&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd
into the following script: (find at RU forum) http://forum.script-coding.com/viewtopic.php?pid=83102#p83102

Code: Select all


Gui +LastFound -Resize -MaximizeBox -MinimizeBox
Gui, Add, Text, x0 y0 w400 h300 vt1 , none
GuiHandle := WinExist()

#include AHKHID.ahk
; plug constants AHKHID
AHKHID_UseConstants()

; Upon receipt of the message, start the function InputMsg
WM_INPUT := 0x00FF
OnMessage(WM_INPUT, "InputMsg")

; RIDEV_INPUTSINK - To accept messages in the background
keydoard := AHKHID_Register(1, 2, GuiHandle, RIDEV_INPUTSINK )

Return 

;-----------------------------------------
; Processing an incoming message

InputMsg(wParam, lParam) {
    Local DevHandle, VKey, sLabel, ProdName 
    
    Critical    ;Or otherwise you could get ERROR_INVALID_HANDLE
    
    ;get II_DEVHANDLE
    DevHandle := AHKHID_GetInputInfo(lParam, II_DEVHANDLE) 
    
    ProdName = % AHKHID_GetDevName(DevHandle, True) ;имя устройства    
    
    /* из example_1.ahk
        my_264_Keys \\?\HID#VID_04D9&PID_FC41&MI_01#9&406d4c2&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
        my_173_Keys \\?\HID#VID_09DA&PID_90C0&MI_00&Col01#8&23ae9689&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
        если имя устройства как у моей клавиатуры
    */
    if ProdName = \\?\HID#VID_04D9&PID_FC41&MI_01#9&406d4c2&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
    {
        ToolTip, my_264_Keys ;not work
    }
    if ProdName = \\?\HID#VID_09DA&PID_90C0&MI_00&Col01#8&23ae9689&0&0000#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}
    {
        ToolTip, my_173_Keys ;not work
    }

	;obviously, not work because it is not my keyboard, but logic for example
    if ProdName = \\?\HID#VID_0518&PID_0001&MI_01&Col01#8&3125ebc9&0&0000#{378de44c-56ef-11d1-bc8c-00a0c91405dd}
    {
        
        ; We get the button key
        VKey = % AHKHID_GetInputInfo(lParam, II_KBD_VKEY)

        ; We get the name of the procedure of this button
        sLabel := "Key_" VKey
        
        ; If there is such a procedure, we call it
        If IsLabel(sLabel)
            Gosub, %sLabel%
            
    }
}

Sound() {
    SoundPlay, %A_WinDir%\Media\ding.wav
}

;------------------------------------------------------------- appoint keys
;keyboard scroll up
Key_120:
    SoundSet +5
    Send, {WheelDown}
    Sound()
Return

;keyboard scroll down
Key_65416:
    SoundSet -5
    Send, {WheelUp}
    Sound()
Return


1. Where can I get my key codes? Like Key_120, Key_65416.
2. And how to sign the buttons correctly?

3. It would be good to know the experience of other Oscar product owners (not only keyboards, but also mice).

4. Or maybe there is a more officient way to bind special keys in AHK without AHKHID?
Attachments
osc.png
osc.png (495.2 KiB) Viewed 293 times

Return to “Ask for Help (v1)”