 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Fri May 14, 2010 10:51 pm Post subject: |
|
|
Take a look at the script for the remote control (it's in the second post of this thread).
A basic script template would be like this:
| Code: |
;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()
;Intercept WM_INPUT messages
OnMessage(0xFF, "InputMsg")
;Register the keyboard TLC with RIDEV_INPUTSINK (so that data is received even in the background)
r := AHKHID_Register(1, 6, hGui, RIDEV_INPUTSINK)
Return
InputMsg(wParam, lParam) {
Critical
;Get handle of device
devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
;Get device name
devname := AHKHID_GetDevName(devh, True)
;Make sure it's from my keyboard
If (devname <> "[KeyboardNameFromExample1]")
Return
;Now you're sure that the input is from your keyboard
;You can do what you need to do here (like get keypress info)
} |
|
|
| Back to top |
|
 |
coleprime Guest
|
Posted: Sun Jun 06, 2010 3:07 am Post subject: Setting Constants by function instead of #include |
|
|
I haven't even gotten a chance to fondle what looks to be an amazing script you wrote yet, but if I may make a suggestion? I've been developing an autoplaying/checking/healing script for myself that plays those clickety-clickety online games for me while I sleep/eat/poop/live/etc. (heh...). A User Library of my own functions has been building in the process at %A_MyDocuments%\AutoHotkey\Lib, and I'd recently been looking to expand potential, which led me to your script here. I'd like to put AHKHID.ahk in the Lib folder and forget about it for when I use it.
As we know, #Include can only take %A_ScriptDir%, %A_AppData%, and %A_AppDataCommon%. Hell, there isn't even a %A_UserLibDir%, so I had to create the obvious global vars missing from AHK:
AHK_AhkConstants() {
Global ; Use global vars
A_AhkDir := SubStr(A_AhkPath, 1, InStr(A_AhkPath, "\", 0, 0) - 1)
A_StandardLibDir = %A_AhkDir%\Lib
A_UserLibDir = %A_MyDocuments%\AutoHotkey\Lib
}
Anyway, I've noticed that the following lines exist in even your example.ahk files:
;You have to put the #Include line in the auto-execute section because of the constants used.
#Include %A_ScriptDir%\AHKHID.ahk
...and this factor is still making true Library status impossible (as in: I don't want to have to leave it in my script dir, and I don't want to directly reference my Lib folder in my scripts). Might you make the following changes to AHKHID.ahk?
Add this...
OR AHKHID_SetConstants()
...in this comment line at [XXX]...
You have to put the #Include line [XXX] in the auto-execute section if you would like to use the constants.
Add this line...
SETCONSTANTS:
...before here...
;___________________________________
;Flags you can use in AHKHID_GetDevInfo
Add this function...
AHKHID_SetConstants() {
Global
If !(RI_MOUSE_WHEEL)
Gosub SETCONSTANTS
}
Now you can leave AHKHID.ahk in your Library folder and all your executing scripts would henceforth include the following lines instead:
;You have to put the AHKHID_SetConstants() line in the auto-execute section because of the constants used.
AHKHID_SetConstants()
In practice, my changes don't even break the #include method, but gives it true Library status. I can't wait to use your script in mine though, thanks so much for all your hard work.
-Cole |
|
| Back to top |
|
 |
coleprime
Joined: 06 Jun 2010 Posts: 1
|
Posted: Sun Jun 06, 2010 3:14 am Post subject: Setting Constants by function instead of #include |
|
|
Edit: I made my post a bit tidier, sorry I hadn't used phpBB in a while. Would a mod remove my last post for cleanliness please?
I haven't even gotten a chance yet to fondle what looks to be an amazing script you've written, but if I may make a suggestion? I've been developing an autoplaying/checking/healing script for myself that plays those clickety-clickety online games for me while I sleep/eat/poop/live/etc. (heh... just my library file has grown over the past 2 months to 37k, or 28k with dox & changelog removed). A User Library of my own functions has been building in the process at %A_MyDocuments%\AutoHotkey\Lib, and I'd recently been looking to expand potential, which led me to your script here. I'd like to put AHKHID.ahk in the Lib folder and forget about it for when I use it.
As we know, #Include can only take %A_ScriptDir%, %A_AppData%, and %A_AppDataCommon%. Hell, there isn't even a %A_UserLibDir%, so I had to create the obvious global vars missing from AHK:
| Code: | AHK_AhkConstants() {
Global ; Use global vars
A_AhkDir := SubStr(A_AhkPath, 1, InStr(A_AhkPath, "\", 0, 0) - 1)
A_StandardLibDir = %A_AhkDir%\Lib
A_UserLibDir = %A_MyDocuments%\AutoHotkey\Lib
}
|
Anyway, I've noticed that the following lines exist in even your example.ahk files:
| Code: | ;You have to put the #Include line in the auto-execute section because of the constants used.
#Include %A_ScriptDir%\AHKHID.ahk
|
...and this factor is still making true Library status impossible (as in: I don't want to have to leave it in my script dir, and I don't want to directly reference my Lib folder in my scripts). Might you make the following changes to AHKHID.ahk?
Add this...
| Code: | OR AHKHID_SetConstants()
|
...in this comment line at [XXX]...
| Code: | You have to put the #Include line [XXX] in the auto-execute section if you would like to use the constants.
|
Add this line...
...before here...
| Code: | ;___________________________________
;Flags you can use in AHKHID_GetDevInfo
|
Lastly, add this function...
| Code: | AHKHID_SetConstants() {
Global
If !(RI_MOUSE_WHEEL)
Gosub SETCONSTANTS
}
|
Now you can leave AHKHID.ahk in your Library folder and all your executing scripts would henceforth include the following lines instead:
| Code: | ;You have to put the AHKHID_SetConstants() line in the auto-execute section because of the constants used.
AHKHID_SetConstants()
|
...which is much more universal than #Include D:\Users\Owner\Documents\AutoHotkey\Lib\AHKHID.ahk, especially when sharing my script with friends. In practice, my changes don't even break the #include method, but gives it true Library status. I can't wait to utilize your script with mine though; thanks so much for all your hard work.
-Cole
p.s. You may want to think about setting versions and some simple changelog to your code edits -- made it WAY easier for me to keep track of stuff, let alone if other people use it too. |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Mon Jun 07, 2010 5:04 am Post subject: |
|
|
coleprime, that's a very good idea! I'll update the scripts soon.
Thanks for your input!  |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Tue Jun 08, 2010 5:10 pm Post subject: |
|
|
| OK, I updated AHKHID as well as all the other examples. They now use AHKHID_UseConstants(). |
|
| Back to top |
|
 |
Steffi Guest
|
Posted: Mon Jun 14, 2010 6:39 am Post subject: I can't get it to run |
|
|
Sorry, I'm absolutely new to AHK and hope to solve some of my special button issues.
But when I want to start the Example 1 I get the error "Call to nonexistant function" form AHKHID_UseConstants().
So I put "#Include %A_ScriptDir%\AHKHID.ahk" into Example 1 but now I get the error "The same variable cannot be used for more than one control" in Line 015 vMyTabs.
What do I have to do? |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Mon Jun 14, 2010 3:43 pm Post subject: |
|
|
Hello Steffi,
You can use AHKHID in two ways. You can either put it in one of your library folders, or you can manually #include it.
However, if you put it in one of your library folders and you want to use the constants, you will have to call AHKHID_UseConstants(). If you manually #include it, there is no need to call this function (this is why you were getting the second error, however, I fixed that possibility now).
The Examples assume that you have AHKHID in one of your library folders. However, you can also add an #include directive (like you did) and it should work fine as well (now).
Make sure to clear your browser's cache before redownloading AHKHID. |
|
| Back to top |
|
 |
Steffi Guest
|
Posted: Tue Jun 15, 2010 3:40 am Post subject: next step |
|
|
Thank you very much, it works!
Now, I really spent most of today reading through this thread and AHK documentation and tried scripts in this thread. I failed miserably so far.
What I have so far is:
| Code: | SetTitleMatchMode, 2
#IfWinActive, VLC media
XButton1::send !{left}
XButton2::send !{right}
|
And I'm happy to have gotten that far.
All I want now is to assign !{left} to a button on the bottom of my mouse. Those 5 buttons are a HID device.
The output of those buttons is here:
Please, can someone paste the simplest code with AHKHID here that gives me a basis to start with. Something that assigns a keystroke to one of these actions.
I am totally overwhelmed with all the fancy GUI code here with several conditionals and error treatment. I couldn't figure out which lines I actually need. And none of the scripts did anything after I got the errors resolved even though I added a couple of "msgbox VARIABLE" to see if something is happening - nothing happened.
I think I have to register the device Page 12, Usage 1. Then listen for the 5 byte value and extract the 4th byte. It's either 08, 09 or 0B. 00 is generated upon button release each time.
Shouldn't that be possible within 5 lines? |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Tue Jun 15, 2010 3:39 pm Post subject: Re: next step |
|
|
| Steffi wrote: | | I think I have to register the device Page 12, Usage 1. Then listen for the 5 byte value and extract the 4th byte. It's either 08, 09 or 0B. 00 is generated upon button release each time. |
Well you seem to have the right idea. I'd suggest you read the example scripts and the remote script (in the tutorial) to familiarize yourself with the commands.
| Steffi wrote: | | Shouldn't that be possible within 5 lines? |
Unfortunately, no. There are a few basic things you need to put in place no matter what, and that will always be greater than 5 lines.
Here is an example script. I didn't/couldn't test it but it should work fine.
| Code: |
;This way we get access to the constants
AHKHID_UseConstants()
;This is just so we have a window handle to use
Gui, +LastFound
hGui := WinExist()
;Intercept WM_INPUT messages
OnMessage(0xFF, "InputMsg")
;Register mouse with RIDEV_INPUTSINK (so that data is received even in the background)
r := AHKHID_Register(12, 1, hGui, RIDEV_INPUTSINK)
If Not r { ;Check for error
MsgBox, Registration failed!`n%ErrorLevel%
ExitApp
}
Return
InputMsg(wParam, lParam) {
Local hDevice, iButton, uData
Critical
;Get device handle
hDevice := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
If (hDevice = -1) { ;Check for error
TrayTip, AHKHID, AHKHID_GetInputInfo failed!`n%ErrorLevel%, 5
Return
}
;Make sure it's the mouse (you could also just compare the name instead of all those comparisons)
If (AHKHID_GetDevInfo(hDevice, DI_HID_VENDORID, True) = 1118)
And (AHKHID_GetDevInfo(hDevice, DI_HID_PRODUCTID, True) = 1793) {
;Get the raw data
iButton := AHKHID_GetInputData(lParam, uData)
If (iButton = -1) { ;Check for error
TrayTip, AHKHID, AHKHID_GetInputData failed!`n%ErrorLevel%, 5
Return
}
;Get the button code (at 4th byte)
iButton := NumGet(uData, 3, "uchar")
;Now you can do what you want with the button.
;If you want to map them to a sendinput command, you can do something like:
If (iButton = 8)
SendInput, !{Left}
Else If (iButton = 9)
SendInput, !{Right}
Else If (iButton = 11)
SendInput, !{Up}
;If you would rather have whole subs execute, you can replace the SendInput commands with Gosub commands.
}
} |
|
|
| Back to top |
|
 |
Steffi Guest
|
Posted: Tue Jun 15, 2010 7:38 pm Post subject: amazing! Thank you! |
|
|
Wow, that is soo cool! Thank you! It works and I can't believe I didn't look into AHK earlier. If I had spent all the time looking to assign hotkeys in different software into AHK I could solve all my wishes already.
After I had the code running, I pasted the script into my other hotkey file under #IfWinActive, VLC.
Of course that didn't work (because of autoexecute and return which i don't understand yet).
So I have to use IfWinActive under the button-assignment.
But would it make sense (if possible) to have the whole script under an "IfWinActive" so that it is not running all the time? Isn't it checking for inputs and registering the HID all the time and thus using up ressources? I only need it while VLC is running.
Of course I could just start the script together with VLC, but I'm curious if my idea about ressources is right and I want to have all my (future) scripts and hotkeys in one file running all the time. |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Wed Jun 16, 2010 4:16 am Post subject: Re: amazing! Thank you! |
|
|
Glad to hear that it works!
| Steffi wrote: | But would it make sense (if possible) to have the whole script under an "IfWinActive" so that it is not running all the time? Isn't it checking for inputs and registering the HID all the time and thus using up ressources? I only need it while VLC is running.
Of course I could just start the script together with VLC, but I'm curious if my idea about ressources is right and I want to have all my (future) scripts and hotkeys in one file running all the time. |
Ressource consumption shouldn't be an issue. You can check the footprint with this to see for yourself. Like you said, the most "efficient" (not as pretty in terms of implementation/practicality) approach would be to start it up at the same time as VLC and end it when VLC ends.
But I think that if you have a main script running all the time anyway, it would make more sense to merge them. To do so, simply make sure that the auto-execute section of the script is part of your main script's auto-execute section, and then you can put the InputMsg() function anywhere you want.
If you're really concerned about memory, you could try registering the TLC only when VLC starts, and unregistering when VLC ends (you do this using AHKHID_Register with the RIDEV_REMOVE flag). But then, you would have to have some kind of monitoring loop (unless you only launch VLC with your main script, in which case it's easier to do this without a loop).
Hope this helps! |
|
| Back to top |
|
 |
Big Digger
Joined: 07 Feb 2009 Posts: 43
|
Posted: Sat Jul 03, 2010 7:41 am Post subject: |
|
|
It is possible to detect with AHKHID when the keypresses occurs on the numpad or not? I mean the following virtual keys:
| Code: | VK_RETURN (0x0D)
ENTER key
VK_PRIOR (0x21)
PAGE UP key
VK_NEXT (0x22)
PAGE DOWN key
VK_HOME (0x24)
HOME key
VK_LEFT (0x25)
LEFT ARROW key
VK_UP (0x26)
UP ARROW key
VK_RIGHT (0x27)
RIGHT ARROW key
VK_DOWN (0x28)
DOWN ARROW key |
AHKHID always returns the same value of the Flags, whereas Micha's DLL returns a different values:
| Code: | ; Enter (AHKHID)
; NumpadEnter (AHKHID)
MakeCode: 28 Flags: 1 VKey: 13 Message: 256 ExtraInfo: 0
MakeCode: 28 Flags: 1 VKey: 13 Message: 257 ExtraInfo: 0
; Enter (AutohotkeyRemoteControl.dll)
MakeCode: 28 Flags: 0 VKey: 13 Message: 256 ExtraInfo: 0
MakeCode: 28 Flags: 1 VKey: 13 Message: 257 ExtraInfo: 0
; NumpadEnter (AutohotkeyRemoteControl.dll)
MakeCode: 28 Flags: 2 VKey: 13 Message: 256 ExtraInfo: 0
MakeCode: 28 Flags: 3 VKey: 13 Message: 257 ExtraInfo: 0
; PgUp (AHKHID)
; NumpadPgUp (AHKHID)
MakeCode: 73 Flags: 1 VKey: 33 Message: 256 ExtraInfo: 0
MakeCode: 73 Flags: 1 VKey: 33 Message: 257 ExtraInfo: 0
; PgUp (AutohotkeyRemoteControl.dll)
MakeCode: 73 Flags: 2 VKey: 33 Message: 256 ExtraInfo: 0
MakeCode: 73 Flags: 3 VKey: 33 Message: 257 ExtraInfo: 0
; NumpadPgUp (AutohotkeyRemoteControl.dll)
MakeCode: 73 Flags: 0 VKey: 33 Message: 256 ExtraInfo: 0
MakeCode: 73 Flags: 1 VKey: 33 Message: 257 ExtraInfo: 0
; PgDn (AHKHID)
; NumpadPgDn (AHKHID)
MakeCode: 81 Flags: 1 VKey: 34 Message: 256 ExtraInfo: 0
MakeCode: 81 Flags: 1 VKey: 34 Message: 257 ExtraInfo: 0
; PgDn (AutohotkeyRemoteControl.dll)
MakeCode: 81 Flags: 2 VKey: 34 Message: 256 ExtraInfo: 0
MakeCode: 81 Flags: 3 VKey: 34 Message: 257 ExtraInfo: 0
; NumpadPgDn (AutohotkeyRemoteControl.dll)
MakeCode: 81 Flags: 0 VKey: 34 Message: 256 ExtraInfo: 0
MakeCode: 81 Flags: 1 VKey: 34 Message: 257 ExtraInfo: 0
; Home (AHKHID)
; NumpadHome (AHKHID)
MakeCode: 71 Flags: 1 VKey: 36 Message: 256 ExtraInfo: 0
MakeCode: 71 Flags: 1 VKey: 36 Message: 257 ExtraInfo: 0
; Home (AutohotkeyRemoteControl.dll)
MakeCode: 71 Flags: 2 VKey: 36 Message: 256 ExtraInfo: 0
MakeCode: 71 Flags: 3 VKey: 36 Message: 257 ExtraInfo: 0
; NumpadHome (AutohotkeyRemoteControl.dll)
MakeCode: 71 Flags: 0 VKey: 36 Message: 256 ExtraInfo: 0
MakeCode: 71 Flags: 1 VKey: 36 Message: 257 ExtraInfo: 0
; Left (AHKHID)
; NumpadLeft (AHKHID)
MakeCode: 75 Flags: 1 VKey: 37 Message: 256 ExtraInfo: 0
MakeCode: 75 Flags: 1 VKey: 37 Message: 257 ExtraInfo: 0
; Left (AutohotkeyRemoteControl.dll)
MakeCode: 75 Flags: 2 VKey: 37 Message: 256 ExtraInfo: 0
MakeCode: 75 Flags: 3 VKey: 37 Message: 257 ExtraInfo: 0
; NumpadLeft (AutohotkeyRemoteControl.dll)
MakeCode: 75 Flags: 0 VKey: 37 Message: 256 ExtraInfo: 0
MakeCode: 75 Flags: 1 VKey: 37 Message: 257 ExtraInfo: 0
; Up (AHKHID)
; NumpadUp (AHKHID)
MakeCode: 72 Flags: 1 VKey: 38 Message: 256 ExtraInfo: 0
MakeCode: 72 Flags: 1 VKey: 38 Message: 257 ExtraInfo: 0
; Up (AutohotkeyRemoteControl.dll)
MakeCode: 72 Flags: 2 VKey: 38 Message: 256 ExtraInfo: 0
MakeCode: 72 Flags: 3 VKey: 38 Message: 257 ExtraInfo: 0
; NumpadUp (AutohotkeyRemoteControl.dll)
MakeCode: 72 Flags: 0 VKey: 38 Message: 256 ExtraInfo: 0
MakeCode: 72 Flags: 1 VKey: 38 Message: 257 ExtraInfo: 0
; Right (AHKHID)
; NumpadRight (AHKHID)
MakeCode: 77 Flags: 1 VKey: 39 Message: 256 ExtraInfo: 0
MakeCode: 77 Flags: 1 VKey: 39 Message: 257 ExtraInfo: 0
; Right (AutohotkeyRemoteControl.dll)
MakeCode: 77 Flags: 2 VKey: 39 Message: 256 ExtraInfo: 0
MakeCode: 77 Flags: 3 VKey: 39 Message: 257 ExtraInfo: 0
; NumpadRight (AutohotkeyRemoteControl.dll)
MakeCode: 77 Flags: 0 VKey: 39 Message: 256 ExtraInfo: 0
MakeCode: 77 Flags: 1 VKey: 39 Message: 257 ExtraInfo: 0
; Down (AHKHID)
; NumpadDown (AHKHID)
MakeCode: 80 Flags: 1 VKey: 40 Message: 256 ExtraInfo: 0
MakeCode: 80 Flags: 1 VKey: 40 Message: 257 ExtraInfo: 0
; Down (AutohotkeyRemoteControl.dll)
MakeCode: 80 Flags: 2 VKey: 40 Message: 256 ExtraInfo: 0
MakeCode: 80 Flags: 3 VKey: 40 Message: 257 ExtraInfo: 0
; NumpadDown (AutohotkeyRemoteControl.dll)
MakeCode: 80 Flags: 0 VKey: 40 Message: 256 ExtraInfo: 0
MakeCode: 80 Flags: 1 VKey: 40 Message: 257 ExtraInfo: 0 |
|
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 580
|
Posted: Sun Jul 04, 2010 4:58 am Post subject: |
|
|
Hey Big Digger,
Thanks for reporting this. Turns out I had a typo in Example 2. I fixed it now, so it should show the proper values for Flags. |
|
| Back to top |
|
 |
Big Digger
Joined: 07 Feb 2009 Posts: 43
|
Posted: Thu Jul 22, 2010 10:28 am Post subject: USBTrace |
|
|
Recently I found a very interesting application at http://www.sysnucleus.com/
| Quote: | | USBTrace is an easy to use and powerful USB analyzer. USBTrace can monitor USB transactions at host controllers, hubs and devices. This is a 100% software product. USBTrace supports Windows 2000, XP, 2003/2008 Server, Vista & Windows 7 operating systems and works with USB 1.x, 2.0 and 3.0 (low, full, high & super speed) host controllers, hubs and devices. |
As you can see on the screenshot it allows easy recognize buttons.
The data comes even if I uninstall all HID devices (keyboard, mouse and other) corresponding to my remote control.
The data comes even for the 'power' and 'toggle' buttons wich are not recognized in any other ways.
| Quote: | | USBTrace is one of those few USB monitoring tools which does not use filter drivers to capture USB traffic. |
Maybe it is possible to capture data from an USB input interrupt pipe (endpoint) with AutoHotkey by calling API or some 3rd party dll? |
|
| Back to top |
|
 |
cracksloth Guest
|
Posted: Thu Aug 05, 2010 8:39 pm Post subject: can someone help? |
|
|
I was wondering if someone could help me out. Basically, I'm trying to create a quick test script based off of TheGood's remote script that will just paste the raw values and then press enter. I wanted to use this method rather than the recommended editing of Example #2 because when I get it to work, I can just continue building on the same script to accomplish what I need.
Also, it took me forever to figure out that the remote example in the second post no longer works with the AHKHID version in the first post because of the recent addition of the prefix AHKHID rather than the old prefix HID. For the inexperienced (like me), it was a pretty frustrating experience of massive trial and error!! blah!
Anyway, my code is below. Can anyone figure out why I'm not getting the code? It just pastes " " after every keypress.
| Code: | #Include AHKHID.ahk
;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()
;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")
;Register the keyboard TLC with RIDEV_INPUTSINK (so that data is received even in the background)
r := AHKHID_Register(65468, 136, hGui, RIDEV_INPUTSINK)
Return
InputMsg(wParam, lParam) {
Local devh, iKey, sLabel
Critical
;Get handle of device
devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
;Get device name
devname := AHKHID_GetDevName(devh, True)
;Make sure it's from my keyboard
If (devname <> "\\?\HID#VID_0C16&PID_0002&MI_01&Col05#7&2658d195&0&0004#{4d1e55b2-f16f-11cf-88cb-001111000030}")
;Get data
iKey := AHKHID_GetInputData(lParam, uData)
SendInput %iKey% "{Enter}"
Return
;Now you're sure that the input is from your keyboard
;You can do what you need to do here (like get keypress info)
}
|
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|