Jump to content

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

AHKHID - An AHK implementation of the HID functions


  • Please log in to reply
456 replies to this topic
specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
Ok curious1, and anyone else who would like to test this.

Here is a link to my very unfinished all inclusive script. I call it Easy Automation AHK. But I'm needing help, you could say I'm stuck at the beginning. I have not been able to integrate my Other HID script into this yet.

It's a little hard to explain all it's functions, basically it's choose an input source and choose a command. Read the PDF file for a quick demo of how it functions.

Ideally I would like to have a script that registers the Other HID device run in the back ground and use the button in a label or as a hotkey in the main script. That may not be an option, if not I would need to come up with a way to automate inputting the data from the Other HID script into TheGoods media player script.

Here is the link to my script. As I said it's incomplete but most of it is functioning. It's likely full of bugs so let me know if you find any. Also let me know if there is a better way to implement anything I'm doing with it.

A few libraries you will need. I plan to include these with the release version.

DockA - Must have, script will not function without it.

WinAmp.ahk - module will not open without it.
Mouse Gestures - " "

Edit: All the libraries are now included in the download.

I'm sure there are a couple more but I can't think of them right now. I'm running late so I'll add links to the needed libraries later.

And anyone who tries this please remember, I'm still learning scripting, I need input and comments but please be constructive with them. Thanks

Easy Automation HID, An any input, any output, anyone can use automation application.
https://ahknet.autoh...EasyAuto V1.zip

cracksloth
  • Guests
  • Last active:
  • Joined: --
sorry, meant to post my test code:

#SingleInstance force
#Include AHKHID.ahk

;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()

;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")

;Register Remote Control with RIDEV_INPUTSINK (so that data is received even in the background)
r := AHKHID_Register(65468, 136, hGui, RIDEV_INPUTSINK)
p := AHKHID_Register(12, 1, hGui, RIDEV_INPUTSINK)
k := AHKHID_Register(1, 6, hGui, RIDEV_INPUTSINK)


InputMsg(wParam, lParam)
{
    Local devh, iKey, sLabel
   
    Critical
   
    ;Get handle of device
    devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
   
    ;Check for error
    If (devh <> -1) ;Check that it is my remote
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
        And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 3094)
        And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 2)
        And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 544)
        {
        iKey := AHKHID_GetInputData(lParam, uData)
        If (iKey <> -1)
        SendInput % Bin2Hex(&uData, iKey) "{Enter}"
        }
    Else If (devh <> -1)
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEKEYBOARD)
        And (AHKHID_GetDevInfo(devh, DI_KBD_TYPE, True) = 81)
        {
        iKey := AHKHID_GetInputData(lParam, uData)
        If (iKey <> -1)
        SendInput % Bin2Hex(&uData, iKey) "{Enter}"
        }
}

Bin2Hex(addr,len) {
   Static fun
   If (fun = "") {
      

h=8B4C2404578B7C241085FF7E30568B7424108A168AC2C0E804463C0976040437EB02043080E20F88018AC2413C0976040437EB0204308801414F7

5D65EC601005FC3
      VarSetCapacity(fun,StrLen(h)//2)
      Loop % StrLen(h)//2
         NumPut("0x" . SubStr(h,2*A_Index-1,2), fun, A_Index-1, "Char")
   }
   VarSetCapacity(hex,2*len+1)
   dllcall(&fun, "uint",&hex, "uint",addr, "uint",len, "cdecl")
   VarSetCapacity(hex,-1) ; update StrLen
   Return hex
}

this will sent the hex values at every captured press (i use notepad to look at the output). i probably used the wrong terminology because i might actually be registering the keyboard-like device of the remote but the script above seems to get into an endless loop (and eventually crash as soon as any keyboard input is detected). any thoughts?

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

sorry, meant to post my test code:

#SingleInstance force
#Include AHKHID.ahk

;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()

;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")

;Register Remote Control with RIDEV_INPUTSINK (so that data is received even in the background)
r := AHKHID_Register(65468, 136, hGui, RIDEV_INPUTSINK)
p := AHKHID_Register(12, 1, hGui, RIDEV_INPUTSINK)
k := AHKHID_Register(1, 6, hGui, RIDEV_INPUTSINK)


InputMsg(wParam, lParam)
{
    Local devh, iKey, sLabel
   
    Critical
   
    ;Get handle of device
    devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
   
    ;Check for error
    If (devh <> -1) ;Check that it is my remote
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
        And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 3094)
        And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 2)
        And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 544)
        {
        iKey := AHKHID_GetInputData(lParam, uData)
        If (iKey <> -1)
        SendInput % Bin2Hex(&uData, iKey) "{Enter}"
        }
    Else If (devh <> -1)
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEKEYBOARD)
        And (AHKHID_GetDevInfo(devh, DI_KBD_TYPE, True) = 81)
        {
        iKey := AHKHID_GetInputData(lParam, uData)
        If (iKey <> -1)
        SendInput % Bin2Hex(&uData, iKey) "{Enter}"
        }
}

Bin2Hex(addr,len) {
   Static fun
   If (fun = "") {
      

h=8B4C2404578B7C241085FF7E30568B7424108A168AC2C0E804463C0976040437EB02043080E20F88018AC2413C0976040437EB0204308801414F7

5D65EC601005FC3
      VarSetCapacity(fun,StrLen(h)//2)
      Loop % StrLen(h)//2
         NumPut("0x" . SubStr(h,2*A_Index-1,2), fun, A_Index-1, "Char")
   }
   VarSetCapacity(hex,2*len+1)
   dllcall(&fun, "uint",&hex, "uint",addr, "uint",len, "cdecl")
   VarSetCapacity(hex,-1) ; update StrLen
   Return hex
}

this will sent the hex values at every captured press (i use notepad to look at the output). i probably used the wrong terminology because i might actually be registering the keyboard-like device of the remote but the script above seems to get into an endless loop (and eventually crash as soon as any keyboard input is detected). any thoughts?


I don't have time to look at all of this right now but I will later tonight. 1rst try removing the mouse usage/usage page line 1-6. The mouse sends a lot of information every time it moves so that may be making it look like an endless loop.

Edit:
My plans were canceled so I took a look at this but couldn't make it work on my machine. Likely because I'm new to scripting and don't know how your sending out to notepad or because I don't have notepad on my computer.

At the risk of sounding pushy I would suggest using my script to gather this information. It will show the hex data and any information being sent on any of the 8 bytes in decimal format, which is what is used to make labels, and has the option to export all this to a log file. This lets you see if the output of a control changes based on the output of another control. It should be much simpler to use and show more information than the script your using. I've uploaded it to ahk.net so you don't have to copy and paste.

https://ahknet.autoh...D info V1.0.ahk

cracksloth
  • Guests
  • Last active:
  • Joined: --
well, i've used your script but (as i think you know) the Gyration remote is made up of multiple devices and i need the 1,6 device because it is what delivers the number keys on my remote (as determined by AHKHID Example 2). did you not run into this problem with your Gyration remote? your script does not show 1,6 devices, right? i use the full hex value as labels in order to simplify the script. also, the script i posted will work in any application that supports text input. when you press a key, it pastes the hex value into whatever program is active so it will work in any text editor that you may use.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
Ok, now I understand what your trying to do and sorry about before, the usage/usage page 1-6 is keyboard not mouse, but I assume you figured that out already. Also I had a typo in my device info which is why I couldn't get your script to work.

Also the remote I use doesn't have number keys, I found that one too heavy to use as a mouse on a daily basis, and the only mouse I use is the remote. With that said...

I dug out my Gyration remote that has number keys and yes they are seen on 1-6. So without doing any further testing I'm thinking that the reason your script is not registering 1-6 is because it only sees devices that are not mice or keyboards, just a theory.

But since it is seen as a keyboard can't you use the number keys as HotKeys? 1234567890, those numbers were typed by my remote so it should be possible to use them as hotkeys. Try putting numbers into an application with your remote. I'm not sure as to the method but there is a way to have AHK differentiate between keyboards and only use hotkeys from one of them. I believe that is mentioned in this topic somewhere.

If this doesn't help let me know and I'll brainstorm some more.

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
curious1 if your still around please look at the first post on page 19. I posted some test for my new script I would like some input on.

http://www.autohotke...41397&start=270

cracksloth
  • Guests
  • Last active:
  • Joined: --
thanks for the help, specter! yes, my remote does type numbers but i didn't want to remap the number keys because i still wanted to have the original key functions on my dedicated keyboard. i wasn't aware that

there is a way to have AHK differentiate between keyboards and only use hotkeys from one of them

so i will definitely have to figure that out (i missed it in the first quick read through of this thread).

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

thanks for the help, specter! yes, my remote does type numbers but i didn't want to remap the number keys because i still wanted to have the original key functions on my dedicated keyboard. i wasn't aware that

there is a way to have AHK differentiate between keyboards and only use hotkeys from one of them

so i will definitely have to figure that out (i missed it in the first quick read through of this thread).


Did you look at the keys in key history to see how they were seen by ahk? That may help differentiate them.

curious1
  • Guests
  • Last active:
  • Joined: --
Specter333, I have been away and just got back to this. I will take a look and give you some feedback soon.

curious1
  • Guests
  • Last active:
  • Joined: --
Spectre333, I tried your script but ran into a few things. I don't know which version or where you got DockA, Or winamp.ahk. Also, I need MG_recognize, which I couldn't easily find. If you would, let me know where those are so I can give your hard work a test drive. Best to you.

cracksloth
  • Guests
  • Last active:
  • Joined: --
i am still having a bit of trouble with some of TheGood's code. in particular the solutions presented
here. basically, i am trying to get the number keys on my remote to perform a function but i want my keyboard keys to behave normally. unfortunately i cannot distinguish my remote from my keyboard so it looks like i'll have to try TheGood's suggestion from his first post referencing the link above. i've tried the code below with no success. it makes me wonder if anyone has tested that code (although i am using AHK_L if that makes a difference). TheGood insinuates that it will work but i am having bad luck with it. according to TheGood's recommendation, the code below should stop the number 1. when it is pressed by my remote, it should:
SendInput %iKey% "{Enter}"
when it is pressed by my keyboard (key = 49) it should:
SendInput b

it seems using:
$1::Return
will totally prevent the keypress from being registered by AHKHID (so pressing the number 1 on either my remote or keyboard has no effect). on the other hand:
1::Return
will allow AHKHID to process the event but it will enter a loop as soon as the "1" key on my keyboard is pressed. I can solve this hotkey loop by making the script use:
SendPlay 1
rather than
SendInput 1

can anyone think of a situation where it would be a disadvantage to modify that code to use my changes:
1::Return
and
SendPlay 1

am I the only one to experience this problem with TheGood's recommendation? is it because i am using AHK_L?

finally, this could be made much simpler for me if AHKHID could distinguish using:
And (AHKHID_GetDevInfo(devh, DI_KBD_NUMBEROFKEYSTOTAL, True) = 110)
because my remote reports a different number of keys than my keyboard. unfortunately, this does not seem to work for me. can anyone else distinguish using that criteria?

any thoughts are certainly welcome (especially TheGood's if he is still around).


-cs



#SingleInstance force
#Include AHKHID.ahk

;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()

;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")

;Register Remote Control with RIDEV_INPUTSINK (so that data is received even in the background)
r := AHKHID_Register(1, 6, hGui, RIDEV_INPUTSINK)

$1::Return

InputMsg(wParam, lParam)
{
    Local devh, iKey, sLabel
   
    Critical
   
    devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
   
    ;Check for error
    If (devh <> -1)
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEKEYBOARD)
        And (AHKHID_GetDevInfo(devh, DI_KBD_TYPE, True) = 81)
;        And (AHKHID_GetDevInfo(devh, DI_KBD_NUMBEROFKEYSTOTAL, True) = 110)
        {
        iKey := AHKHID_GetInputData(lParam, uData)
        If (iKey <> -1)
        Msgbox Success!
        }
    Else
        {
        key := AHKHID_GetInputInfo(lParam, II_KBD_VKEY)
        If (key = 49)   ;1
        SendInput 1
        }
}


Bin2Hex(addr,len) {
   Static fun
   If (fun = "") {
      

h=8B4C2404578B7C241085FF7E30568B7424108A168AC2C0E804463C0976040437EB02043080E20F88018AC2413C0976040437E

B0204308801414F75D65EC601005FC3
      VarSetCapacity(fun,StrLen(h)//2)
      Loop % StrLen(h)//2
         NumPut("0x" . SubStr(h,2*A_Index-1,2), fun, A_Index-1, "Char")
   }
   VarSetCapacity(hex,2*len+1)
   dllcall(&fun, "uint",&hex, "uint",addr, "uint",len, "cdecl")
   VarSetCapacity(hex,-1) ; update StrLen
   Return hex
}


cracksloth
  • Guests
  • Last active:
  • Joined: --
sorry, instead of:
when it is pressed by my remote, it should:
SendInput %iKey% "{Enter}"

it should read:
when it is pressed by my remote, it should:
Msgbox Success!

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007

Spectre333, I tried your script but ran into a few things. I don't know which version or where you got DockA, Or winamp.ahk. Also, I need MG_recognize, which I couldn't easily find. If you would, let me know where those are so I can give your hard work a test drive. Best to you.


I updated the other day, all the libraries are now in the zip. It's also a lot further along with a few more modules than the version you have. I figured out yesterday how to implement AHKHID, I'll try to upload that version tonight.

Now that I have it this far along I've learned enough to think I need to start over again. I do believe I can make it easier to use and add modules to.

Still any comments or suggestions you have will be appreciated.
Thanks

specter333
  • Members
  • 627 posts
  • Last active: Oct 07 2016 07:43 AM
  • Joined: 15 Jan 2007
curious1,

It took me a couple of days but I uploaded the script with AHKHID integrated, at least partially. As I said before all libraries needed are included in the download, just copy them to your lib folder.

This is the last update I'm going to do to this version. I'm going to "attempt" to rewrite the editor to make it more efficient and user friendly and hopefully then I'll be ready to post this in it's own thread.

If you have time to test this, or anyone else who cares to take a look, I would still be happy to get some comments and suggestions.

The download link is in a previous post,
http://www.autohotke...41397&start=270

curious1
  • Guests
  • Last active:
  • Joined: --
Good luck with your re-write. I did try out the script. Unfortunately I cannot get Mousegestures to run, I will look at the authors post to see if I can figure out why. I'm trying it on an XP pro machine. Obviously I have the libraries copied into Autohotkey. But i cannot launch it individually either.

BTW, I didn't wee where you were calling MouseGestures in your code before you call the function.

let me know if I have missed something, in the meantime, I'll see what I can figure out.