Need help comparing a variable to a hex value Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
jnkettenring
Posts: 2
Joined: 16 Jul 2018, 13:04

Need help comparing a variable to a hex value

20 Jul 2018, 13:50

Hello,

I'm trying to map some unique buttons on a Natural Ergonomic Keyboard 4000 v1.0. I've gotten the all the buttons I want mapped, working, except the "("
and ")" buttons. Their ID numbers are "010000B600010000" and "010000B700010000" respectively. I am assuming the issue is because these ID number have letters in them as well, and the way i have it is trying to compare them as decimal numbers.
Can someone please tell me how I should be comparing these values?

Snippet of my code is below:

Code: Select all

InputMsg(wParam, lParam) {
    Local r, h, data 
    Critical    ;Or otherwise you could get ERROR_INVALID_HANDLE
    
		 ;Get handle of device
		devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)

		;Check for error
		If (devh <> -1) ;Check that it is my Natural Ergonomic Keyboard 4000 v1.0
		And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
		And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 1118)
		And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 219)
		And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 371) {

		;Get data
		iKey := AHKHID_GetInputData(lParam, uData)

		;Check for error
		If (iKey <> -1) {
		}
	}
		data := Bin2Hex(&uData, iKey)

		;MsgBox %data% ; Uncomment to view Key ID at keypress
		
		
		; Favorites 1
		If (data == 0100000000050000) {
		MsgBox %data%
		
		;Favorites 2
		} Else If (data == 0100000000090000) {
		MsgBox favorites 2
		
		;Favorites 3
		} Else If (data == 0100000000110000) {
		MsgBox favorites 3
		
		;Favorites 4
		} Else If (data == 0100000000210000) {
		MsgBox favorites 4
		
		;Favorites 5
		} Else If (data == 0100000000410000) {
		MsgBox favorites 5
		
		;Favorites =
		} Else If (data == 0100006700010000) {
		MsgBox Equal Sign
		
		;Favorites (
		} Else If (data == 010000B600010000) {
		MsgBox j
		
		;Favorites )
		} Else If (data == 010000B700010000) {
		MsgBox k
	
		}  
		
		
		return
		
}







;By Laszlo, adapted by TheGood
;http://www.autohotkey.com/forum/viewtopic.php?p=377086#377086
Bin2Hex(addr,len) {
    Static fun, ptr 
    If (fun = "") {
        If A_IsUnicode
            If (A_PtrSize = 8)
                h=4533c94c8bd14585c07e63458bd86690440fb60248ffc2418bc9410fb6c0c0e8043c090fb6c00f97c14180e00f66f7d96683e1076603c8410fb6c06683c1304180f8096641890a418bc90f97c166f7d94983c2046683e1076603c86683c13049ffcb6641894afe75a76645890ac366448909c3
            Else h=558B6C241085ED7E5F568B74240C578B7C24148A078AC8C0E90447BA090000003AD11BD2F7DA66F7DA0FB6C96683E2076603D16683C230668916240FB2093AD01BC9F7D966F7D96683E1070FB6D06603CA6683C13066894E0283C6044D75B433C05F6689065E5DC38B54240833C966890A5DC3
        Else h=558B6C241085ED7E45568B74240C578B7C24148A078AC8C0E9044780F9090F97C2F6DA80E20702D1240F80C2303C090F97C1F6D980E10702C880C1308816884E0183C6024D75CC5FC606005E5DC38B542408C602005DC3
        VarSetCapacity(fun, StrLen(h) // 2)
        Loop % StrLen(h) // 2
            NumPut("0x" . SubStr(h, 2 * A_Index - 1, 2), fun, A_Index - 1, "Char")
        ptr := A_PtrSize ? "Ptr" : "UInt"
        DllCall("VirtualProtect", ptr, &fun, ptr, VarSetCapacity(fun), "UInt", 0x40, "UInt*", 0)
    }
    VarSetCapacity(hex, A_IsUnicode ? 4 * len + 2 : 2 * len + 1)
    DllCall(&fun, ptr, &hex, ptr, addr, "UInt", len, "CDecl")
    VarSetCapacity(hex, -1) ; update StrLen
    Return hex
}
trust_me
Posts: 57
Joined: 29 Jul 2017, 10:46

Re: Need help comparing a variable to a hex value  Topic is solved

21 Jul 2018, 02:10

You can compare all your values as strings ( numbers or mixed with letters)

Code: Select all

data = 010000B600010000

if  (data="010000B600010000")
msgbox found
else
msgbox not found
jnkettenring
Posts: 2
Joined: 16 Jul 2018, 13:04

Re: Need help comparing a variable to a hex value

23 Jul 2018, 10:07

Thank you! This worked perfectly for what I needed.

Return to “Ask For Help”

Who is online

Users browsing this forum: 4stargeneral, TheDewd and 88 guests