 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Maestr0
Joined: 18 Oct 2008 Posts: 24
|
Posted: Tue Sep 15, 2009 10:26 am Post subject: |
|
|
great work!
This solved a problem I had where I was trying to auto-enable/disable the numlock on my laptop, depending whether a USB keyboard was attached.
Here's the script I made, using your code.
For some reason, it won't work right when I put it in one script, so I've made two, a notifier, and a checker/changer.
Comments welcomed.
NOTIFIER (this one is running all the time)
| Code: |
runwait kb_checker.ahk ; -- just in case the keyboard is connected when the script is started
OnMessage(0x219, "notify_change")
return
notify_change(wParam, lParam, msg, hwnd)
{
;outputdebug notify_change(%wParam%, %lParam%, %msg%, %hwnd%)
if msg = 537
runwait kb_checker.ahk
}
|
CHECKER/CHANGER (this one is called by the notifier when a device is added/removed)
| Code: |
#persistent
#singleinstance
#NoTrayIcon
iCount := HID_GetDevCount()
Loop , %icount%
{
HID0 += 1
HID%HID0%_Name := HID_GetDevName(HID0)
HID%HID0%_Type := HID_GetDevType(HID0)
name := HID_GetDevName(HID0)
type := HID_GetDevType(HID0)
if type = 1 ; RIM_TYPEKEYBOARD = 1 means the device is a keyboard.
{
if name contains HID
{
;outputdebug (%icount% : %HID0%) function_check_usb`n%HID0%`n%type% - %name%
SetNumLockState , ON
break
}
}
else
{
;outputdebug (%icount% : %HID0%) Keyboard not found
SetNumLockState , OFF
}
}
exitapp
HID_Initialize(bRefresh = False) {
Static uHIDList, bInitialized := False
If bInitialized And Not bRefresh
Return &uHIDList
;Get the device count
r := DllCall("GetRawInputDeviceList", "UInt", 0, "UInt*", iCount, "UInt", 8)
;Check for error
If (r = -1) Or ErrorLevel {
ErrorLevel = GetRawInputDeviceList call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
;outputdebug (%A_LineNumber%) %errorlevel%
Return -1
}
;Prep var
VarSetCapacity(uHIDList, iCount * 8)
r := DllCall("GetRawInputDeviceList", "UInt", &uHIDList, "UInt*", iCount, "UInt", 8)
If (r = -1) Or ErrorLevel {
ErrorLevel = GetRawInputDeviceList call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
;outputdebug (%A_LineNumber%) %errorlevel%
Return -1
}
bInitialized := True
Return &uHIDList
}
HID_GetDevHandle(i) {
Return NumGet(HID_Initialize(), (i - 1) * 8)
}
HID_GetDevName(i, IsHandle = False) {
RIDI_DEVICENAME := 0x20000007
;Get index if i is handle
h := IsHandle ? i : HID_GetDevHandle(i)
;Get device name length
r := DllCall("GetRawInputDeviceInfo", "UInt", h, "UInt", RIDI_DEVICENAME, "UInt", 0, "UInt*", iLength)
If (r = -1) Or ErrorLevel {
ErrorLevel = GetRawInputDeviceInfo call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
;outputdebug (%A_LineNumber%) %errorlevel%
Return ""
}
;Get device name
VarSetCapacity(s, iLength + 1)
r := DllCall("GetRawInputDeviceInfo", "UInt", h, "UInt", RIDI_DEVICENAME, "Str", s, "UInt*", iLength)
If (r = -1) Or ErrorLevel {
ErrorLevel = GetRawInputDeviceInfo call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
;outputdebug (%A_LineNumber%) %errorlevel%
Return ""
}
Return s
}
HID_GetDevType(i, IsHandle = False) {
Return Not IsHandle ? NumGet(HID_Initialize(), ((i - 1) * 8) + 4)
: NumGet(HID_Initialize(), ((HID_GetDevIndex(i) - 1) * 8) + 4)
}
HID_GetDevCount() {
;Get the device count
r := DllCall("GetRawInputDeviceList", "UInt", 0, "UInt*", iCount, "UInt", 8)
;Check for error
If (r = -1) Or ErrorLevel {
ErrorLevel = GetRawInputDeviceList call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
;outputdebug (%A_LineNumber%) %errorlevel%
Return -1
} Else Return iCount
}
HID_GetDevIndex(Handle) {
Loop % HID_GetDevCount()
If (NumGet(HID_Initialize(), (A_Index - 1) * 8) = Handle)
Return A_Index
Return 0
}
|
|
|
| Back to top |
|
 |
danielburgess
Joined: 22 Sep 2009 Posts: 1
|
Posted: Tue Sep 22, 2009 8:40 am Post subject: Exclusive mode? |
|
|
Just curious, (okay, actually a little more than that) when using RIDEV_INPUTSINK, does it automatically engage the device in the equivalent of DirectX's exclusive mode?
</relevant question>
<rambling>
As previously noted by others, and after looking through Microsoft's actual documentation (which is actually well featured, compared to most of what I've experienced with msdn et all), your interface layer is remarkably well done. (i.e. a tad over my head. )
My testing has been somewhat crude, as I am still in the learning process in AHK general. I am intercepting the raw data at the bluetooth level, and hoping to prevent it from reaching Microsoft's gaming device drivers (which are horribly mapped, sending a constant stream of input to a non-existant analog joystick which, unfortunately, interfaces perfectly with old directx games, rendering them unplayable) |
|
| Back to top |
|
 |
TheGood
Joined: 30 Jul 2007 Posts: 398
|
Posted: Wed Sep 23, 2009 6:26 pm Post subject: Re: Exclusive mode? |
|
|
| danielburgess wrote: | | Just curious, (okay, actually a little more than that) when using RIDEV_INPUTSINK, does it automatically engage the device in the equivalent of DirectX's exclusive mode? |
I'm not sure what that means, because I'm not intimate with DirectX. But if exclusive mode means restrict the device input to your script only (so that other scripts/programs don't see them) then the answer is no. The truth is that any number of program can register itself for input notification, without interfering with other devices.
| danielburgess wrote: | As previously noted by others, and after looking through Microsoft's actual documentation (which is actually well featured, compared to most of what I've experienced with msdn et all), your interface layer is remarkably well done. (i.e. a tad over my head. ) |
Thank you!
| danielburgess wrote: | | My testing has been somewhat crude, as I am still in the learning process in AHK general. I am intercepting the raw data at the bluetooth level, and hoping to prevent it from reaching Microsoft's gaming device drivers (which are horribly mapped, sending a constant stream of input to a non-existant analog joystick which, unfortunately, interfaces perfectly with old directx games, rendering them unplayable) |
Yeah, AHKHID will not allow you to prevent input from reaching other listeners. I have no clue how you would go about doing that (certainly not through the HID interface I exposed with AHKHID). |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 923 Location: Canada
|
Posted: Fri Oct 16, 2009 4:00 pm Post subject: |
|
|
I got this to work with a nintendo Wiimote. Problem is the Roll Pitch, acceration and IR sensors dont work. All the buttons work but anythign that needs a feed wont come up. Any ideas? _________________
I know i have 6 legs. It's cuz I'm special. |
|
| Back to top |
|
 |
bidomo
Joined: 05 Feb 2009 Posts: 36
|
Posted: Wed Oct 21, 2009 7:52 am Post subject: |
|
|
I don't think you can add functionality to the accelerometer or IR without making some mayor changes, which involves a big season of coding, but you can refer to the GlovePIE software (don't know if is open source).
BTW, this little script won't work in Win7 Beta, don't know if it will work later.
soon will find |
|
| Back to top |
|
 |
eryksun Guest
|
Posted: Sat Oct 31, 2009 9:35 pm Post subject: Custom ReportMappingTable |
|
|
| bidomo wrote: | | There's a way to custimize the keys in the remote, included some info about the way it's been sent to windows (as windows is catching them as keyboard), ...You have to modify the RC6MAP.INF file, or create a new one with the info below, don't know if works in vista as I edited the regidtry directly, and it works....I've got this info from http://mediacenterguides.com/sites/default/files/IRCodes_ReportMappingTable_InputINF.pdf |
Thank you a million times over! I wouldn't have had the patience to reverse engineer the "ReportMappingTable" registry entry.
Your info let me create a custom keymap for use with AHKHID. I backed up the original key to a reg file, edited a copy, merged, rebooted, and all worked great. Now I can get key up messages for every button on the remote, using a consistent interface that's separate from the keyboard. I'm using 'consumer controls' for all the buttons on the 1->12 usage. That's almost every remote button, except for a few on the 136->65468 usage (e.g. the green MCE button, DVD, Live TV, and Recorded TV). I use only XBMC and BOXEE (not VMC) on my Vista HTPC, so I didn't bother to preserve Microsoft's codes. Here's the set I created:
| Code: | Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HidIr\Remotes\745a17a0-74d3-11d0-b6fe-00a0c90f57da]
"ReportMappingTable"=hex:\
;
; Usage->UsagePage: 136->65468
;
; 03,0d ;Green MCE
; 03,24 ;DVD
; 03,25 ;TV Live
; 03,48 ;TV Recorded
;
; Usage->UsagePage: 1->12
;
; Suspend,Suspend,Print,?
0c,00,00,00,01,00,50,\
2a,00,00,00,01,00,51,\
4e,00,00,00,01,00,52,\
6e,00,00,00,01,00,53,\
;
; FF,RW,Play,Rec,Pause,
; Stop,Next,Prev
14,00,00,00,01,00,60,\
15,00,00,00,01,00,61,\
16,00,00,00,01,00,62,\
17,00,00,00,01,00,63,\
18,00,00,00,01,00,64,\
19,00,00,00,01,00,65,\
1a,00,00,00,01,00,66,\
1b,00,00,00,01,00,67,\
;
; Back,Up,Dn,Lt,Rt,OK,Info
23,00,00,00,01,00,70,\
1e,00,00,00,01,00,71,\
1f,00,00,00,01,00,72,\
20,00,00,00,01,00,73,\
21,00,00,00,01,00,74,\
22,00,00,00,01,00,75,\
0f,00,00,00,01,00,76,\
;
; Vol+-,Mute,Ch+-,Guide
; *,#,Clear,Enter
10,00,00,00,01,00,80,\
11,00,00,00,01,00,81,\
0e,00,00,00,01,00,82,\
12,00,00,00,01,00,83,\
13,00,00,00,01,00,84,\
26,00,00,00,01,00,85,\
1d,00,00,00,01,00,86,\
1c,00,00,00,01,00,87,\
0a,00,00,00,01,00,88,\
0b,00,00,00,01,00,89,\
;
; 0-9
00,00,00,00,01,00,90,\
01,00,00,00,01,00,91,\
02,00,00,00,01,00,92,\
03,00,00,00,01,00,93,\
04,00,00,00,01,00,94,\
05,00,00,00,01,00,95,\
06,00,00,00,01,00,96,\
07,00,00,00,01,00,97,\
08,00,00,00,01,00,98,\
09,00,00,00,01,00,99 |
The second-to-last number (0x00) distinguishes the code on my system since MS only used 08, 09, 9?, b?, c?, and e? in this field. No other programs hooking the HID should get a false match on my codes (I hope). The actual 2-digit hex code for a button is the last number on the line. This comes as the last byte of uData from DataSize=HID_GetInputData(lParam, uData). The set begins at 0x50 because, for me, 0x48 (Recorded TV) is the highest value from the hard-coded usage on 136. I sequenced the buttons in 5 groups of 10 or less (5?,6?,7?,8?,9?). The 0th code is used for key up. In my case the complete key-up code is either 0x0300 (for 136->65468) or 0x020000 (for 1->12), with the last byte equal to 0x00 in both cases. |
|
| Back to top |
|
 |
eryksun Guest
|
Posted: Sat Oct 31, 2009 11:48 pm Post subject: Re: Custom ReportMappingTable |
|
|
| eryksun wrote: | | That's almost every remote button, except for a few on the 136->65468 usage (e.g. the green MCE button, DVD, Live TV, and Recorded TV). |
The system turns out to be more flexible than I at first thought. All of the 136->65468 entries can be overridden with consumer controls. Now I have every button on 1->12 and only have to register the one usage. Very cool.
Current ReportMappingTable:
| Code: | Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HidIr\Remotes\745a17a0-74d3-11d0-b6fe-00a0c90f57da]
"ReportMappingTable"=hex:\
;
; 0-9
00,00,00,00,01,00,00,\
01,00,00,00,01,00,01,\
02,00,00,00,01,00,02,\
03,00,00,00,01,00,03,\
04,00,00,00,01,00,04,\
05,00,00,00,01,00,05,\
06,00,00,00,01,00,06,\
07,00,00,00,01,00,07,\
08,00,00,00,01,00,08,\
09,00,00,00,01,00,09,\
;
; *,#,Clear,Enter
1d,00,00,00,01,00,10,\
1c,00,00,00,01,00,11,\
0a,00,00,00,01,00,12,\
0b,00,00,00,01,00,13,\
;
; Mute,Vol+-,Ch+-
0e,00,00,00,01,00,20,\
10,00,00,00,01,00,21,\
11,00,00,00,01,00,22,\
12,00,00,00,01,00,23,\
13,00,00,00,01,00,24,\
;
; FF,RW,Play,Rec,Pause,
; Stop,Next,Prev
14,00,00,00,01,00,30,\
15,00,00,00,01,00,31,\
16,00,00,00,01,00,32,\
17,00,00,00,01,00,33,\
18,00,00,00,01,00,34,\
19,00,00,00,01,00,35,\
1a,00,00,00,01,00,36,\
1b,00,00,00,01,00,37,\
;
; U,D,L,R,OK,Back
1e,00,00,00,01,00,40,\
1f,00,00,00,01,00,41,\
20,00,00,00,01,00,42,\
21,00,00,00,01,00,43,\
22,00,00,00,01,00,44,\
23,00,00,00,01,00,45,\
;
; Suspend,MCE,Info,
; TVRec,Guide,TVLive,DVD
0c,00,00,00,01,00,50,\
0d,00,00,00,01,00,51,\
0f,00,00,00,01,00,52,\
48,00,00,00,01,00,53,\
26,00,00,00,01,00,54,\
25,00,00,00,01,00,55,\
24,00,00,00,01,00,56 |
|
|
| Back to top |
|
 |
bidomo
Joined: 05 Feb 2009 Posts: 36
|
Posted: Fri Nov 06, 2009 5:15 pm Post subject: |
|
|
Is great to see it was helpful to you, hopefully others.
My 7 copy is in home (promotional price $29.00 USD for students in Mexico), but seems I'm gonna still using vista for now. |
|
| Back to top |
|
 |
rhinox202
Joined: 23 Apr 2009 Posts: 13
|
Posted: Sun Nov 15, 2009 6:50 am Post subject: |
|
|
Great program!
Last edited by rhinox202 on Thu Nov 26, 2009 2:12 am; edited 1 time in total |
|
| Back to top |
|
 |
gbk
Joined: 26 Sep 2006 Posts: 5
|
Posted: Wed Nov 18, 2009 6:16 pm Post subject: Second Keyboard |
|
|
Hey,
I've seen this problem on this thread but no solution:
I want to remap the keys from a second keyboard.
All works fine but is there a way to block the "output" of the second keyboard too?
For example:
If I get the II_KBD_VKEY Code for "S" and remap it to something else the second keyboard still sends the "S" letter. |
|
| Back to top |
|
 |
bidomo
Joined: 05 Feb 2009 Posts: 36
|
Posted: Fri Nov 20, 2009 7:32 am Post subject: Re: Second Keyboard |
|
|
| gbk wrote: |
If I get the II_KBD_VKEY Code for "S" and remap it to something else the second keyboard still sends the "S" letter. |
I didn't get that at all, but...
Seems to me you're trying to use the 2nd keybd to do something specific, with no relation to what the keyboard is doing...
If, somehow, you are able to disable the input part of that keyboard, it will be totally dummy, but its HID relative driver should still be installed, that way, you will be able to totally reprogram it.
It's the same for me with the remote, I have to disable keyboard input in it (from registry), and I can fully reprogram it, so when I press one key, it will do what I want but will not make the default acction of that key anymore. |
|
| Back to top |
|
 |
gbk
Joined: 26 Sep 2006 Posts: 5
|
Posted: Fri Nov 20, 2009 9:15 am Post subject: |
|
|
| bidomo wrote: |
It's the same for me with the remote, I have to disable keyboard input in it (from registry), and I can fully reprogram it
|
Can I disable the second keyboard form the registry? |
|
| Back to top |
|
 |
LastCallAgain
Joined: 20 Nov 2009 Posts: 6
|
Posted: Fri Nov 20, 2009 3:16 pm Post subject: Re: AHKHID - An AHK implementation of the HID functions |
|
|
I've been searching this forum in vain for a way to map my Logitech G11's '"G" keys (other than simply assigning them to other key combinations) and I think this should do the trick!
So far using TheGood's examples I've been able to find the MakeCode and VKeys for all but two of the G keys (for some reason G11 and G12 aren't bringing up any data)
However, (1) I would hate to reinvent the wheel, so to speak, and (2) I'm fairly new to AHK... so before I go much farther I was just wondering if anyone else had done something similar? I don't want to be 'that guy' who asks other people to do all the work for him, but if it's already out there... _________________ --------------------------------------------------
Computers make it easier to do a lot of
things, but most of the things they make
it easier to do don't need to be done.
--Andy Rooney
--------------------------------------------------
Last edited by LastCallAgain on Thu Dec 10, 2009 3:59 am; edited 1 time in total |
|
| Back to top |
|
 |
bidomo
Joined: 05 Feb 2009 Posts: 36
|
Posted: Sat Nov 21, 2009 5:40 am Post subject: |
|
|
| gbk wrote: |
Can I disable the second keyboard form the registry? |
there must be a way... |
|
| Back to top |
|
 |
rhinox202
Joined: 23 Apr 2009 Posts: 13
|
Posted: Wed Nov 25, 2009 11:20 pm Post subject: Send Some Commands Directly to MCE (SOLVED) |
|
|
I was able to piece together the following commands by using the information found on http://www.eventghost.org/forum/viewtopic.php?f=2&t=319 and tinkering with AHK Messenger http://www.autohotkey.com/forum/topic32142.html. The following information allows commands to be sent directly to MCE without activating it. I would like to be able to get all the other keys working like this, but so far have not been able to. If someone else could figure it out with the provided information, that would be cool. For the time being... enjoy!
Bob
; Record
PostMessage, 0x0319, 0, 3145728,, ahk_class eHome Render Window
; Play
PostMessage, 0x0319, 0, 3014656,, ahk_class eHome Render Window
; Pause/Play
PostMessage, 0x0319, 0, 917504,, ahk_class eHome Render Window
; Stop
PostMessage, 0x0319, 0, 851968,, ahk_class eHome Render Window
; Replay (only works for Music, no TV)
PostMessage, 0x0319, 0, 786432,, ahk_class eHome Render Window
; Skip (only works for Music, no TV)
PostMessage, 0x0319, 0, 720896,, ahk_class eHome Render Window
; Rewind
PostMessage, 0x0319, 0, 3276800,, ahk_class eHome Render Window
; Fast Forward
PostMessage, 0x0319, 0, 3211264,, ahk_class eHome Render Window
; Back
PostMessage, 0x0319, 0, 65536,, ahk_class eHome Render Window
; Mute
PostMessage, 0x0319, 0, 524288,, ahk_class eHome Render Window
; Volume Up
PostMessage, 0x0319, 0, 655360,, ahk_class eHome Render Window
; Volume Down
PostMessage, 0x0319, 0, 589824,, ahk_class eHome Render Window
; Channel Up (doesn't appear to work)
PostMessage, 0x0319, 0, 3342336,, ahk_class eHome Render Window
; Channel Down (doesn't appear to work)
PostMessage, 0x0319, 0, 3407872,, ahk_class eHome Render Window |
|
| 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
|