Autohotkey had ik al een tijdje geleden ontdekt, daarna vond ik Micha's DLL, en nadat ik er wat mee geëxperimenteerd heb, kan ik nu bijna elke knop van mijn afstandsbediening herprogrammeren.
Eindelijk kan ik de kleurtoetsen voor iets nuttigs gebruiken, en de afstandsbediening in Media Player Classic gebruiken.
Hierbij heb ik het script toegevoegd dat ik momenteel gebruik.
Er zijn nog steeds aspecten aan die ik wil verbeteren, zeker wat Media Player Classic betreft.
Dus als ik nog eens wat extra tijd heb wil ik het gedrag van de FFWD en REWD knoppen meer doen lijken op dat van Mediacenter.
Voor het ontwikkelen van het script heb ik wat hulp gekregen van Micha, hij ontwikkelde het systeem met de aparte INI file.
Het script bestaat uit 3 onderdelen :
Je moet eerst en vooral de DLL downloaden van
http://www.autohotkey.net/~Micha/HIDsupport/Autohotkey.htmlDaarna plak je de volgende lijnen in Kladblok/Notepad en bewaar het geheel als myhotkeys.ahk.
MYHOTKEYS.AHK :
----------------------
;This is the .AHK file, you can name it as you like.
;You now still need the .INI file, in which you will put most commands
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <
myemail@nowhere.com>
;
; Script Function:
; Template AutoHotkey script.
;
; PLEASE DO NOT DELETE THE FOLLOWING LINES
;Path to AutohotkeyRemoteControl.dll
HomePath="C:\Program Files\Autohotkey\AutohotkeyRemoteControl.dll
"
;HomePath=release\AutohotkeyRemoteControl.dll
;Load the dll
hModule := DllCall("LoadLibrary", "str", HomePath) ; Avoids the need for DllCall() in
OnMessage(0x00FF, "InputMsg")
DetectHiddenWindows, on
;SetTimer,UPDATEDSCRIPT,1000
ReadIni()
;Register my device
EditUsage = 136
EditUsagePage = 65468
Gui, Show, x0 y0 h0 w0, Autohotkey HID-Support
;HWND := WinActive("F:\myprg\Win\Autohotkeyremote\Autohotke yRemoteControl\RemoteControl.ahk")
HWND := WinExist("Autohotkey HID-Support")
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
MsgBox RegisterDevice fehlgeschlagen. Errorcode: %errorlevel%
goto cleanup
}
;Register another device
EditUsage = 1
EditUsagePage = 12
nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, EditUsage, INT, EditUsagePage, INT, HWND, "Cdecl UInt")
Winhide, Autohotkey HID-Support
return
InputMsg(wParam, lParam, msg, hwnd)
{
DataSize = 5000
VarSetCapacity(RawData, %DataSize%)
;MsgBox eingetroffen %wParam% %lParam% %msg% %HWND%
;Write something into the var, so the script won't be aborted :
;(g_script.ScriptError("This DllCall requires a prior VarSetCapacity. The program is now unstable and will exit.")
RawData = 1
nRC := DllCall("AutohotkeyRemoteControl\GetWM_INPUTHIDDat a", UINT, wParam, UINT, lParam, "UINT *" , DataSize, "UINT", &RawData, "Cdecl UInt")
if (errorlevel <> 0) || (nRC == -1)
{
MsgBox GetWM_INPUTHIDData fehlgeschlagen. Errorcode: %errorlevel%
goto cleanup
}
loop, %DataSize%
{
Zeichen := ExtractInteger(RawData, A_Index, false, 1)
ifless, Zeichen, 9
{
Zeichen= 0%Zeichen%
}
Vals = %Vals%%Zeichen%
}
;The var Vals contains the values of your remote control.
;In the next block you can jump to the function which sends keys to your app or is doing what you want
;if the desired message arrives. You can name the labels as you want. I used the chars of my remote ctrl
ifequal, vals, 1760000, gosub Playbutton
ifequal, vals, 1770000, gosub Pausebutton
ifequal, vals, 1800000, gosub Rewindbutton
ifequal, vals, 1790000, gosub Fastforwardbutton
ifequal, vals, 1820000, gosub Chapterbackbutton
ifequal, vals, 1810000, gosub Chapterforwardbutton
ifequal, vals, 360200, gosub Backbutton
ifequal, vals, 90200, gosub Infobutton
ifequal, Vals, 9100, gosub Redbutton
ifequal, Vals, 9200, gosub Greenbutton
ifequal, Vals, 9300, gosub Yellowbutton
ifequal, Vals, 9400, gosub Bluebutton
}
return
Playbutton:
Dokey("Play")
return
Pausebutton:
Dokey("Pause")
return
Rewindbutton:
Dokey("Rewind")
return
Fastforwardbutton:
Send a
return
Chapterbackbutton:
Dokey("Chapterback")
return
Chapterforwardbutton:
Dokey("Chapterfwd")
return
Backbutton:
Send ^q
WinGetPos, X,Y,W,H,Open
Coordmode Mouse,Screen
Click 640,380
return
Infobutton:
SetKeyDelay,100
DoKey("Info")
return
Redbutton:
DoKey("Red")
return
Greenbutton:
DoKey("Green")
return
Yellowbutton:
Dokey("Yellow")
return
Bluebutton:
Dokey("Blue")
return
#IfWinActive ahk_class MediaPlayerClassicW
à::
Send ^{NumPad4}
return
&::
Send ^{NumPad8}
return
é::
Send {NumPad8}
return
'::
Send {NumPad4}
return
(::
Send {NumPad5}
return
§::
Send {NumPad6}
return
è::
Send {NumPad1}
return
!::
Send {NumPad2}
return
8::
Send ^{NumPad2}
return
"::
Send {NumPad9}
return
3::
Send ^{NumPad6}
return
#IfWinActive
#IfWinActive ahk_class eHome Render Window
8::
;This actually refers to the asterisk key on the remote
;This button is now remapped to Alt+Enter, which toggles between fullscreen mode and windowed mode
Send !{ENTER}
return
3::
;This actually refers to the # key on the remote
;This button is now remapped to Alt+F4, which closes Mediacenter
Send!{F4}
return
#IfWinActive
cleanup:
DllCall("FreeLibrary", "UInt", hModule) ; It is best to unload the DLL after using it (or before the script exits).
ExitApp
UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
SplashTextOn,,,Updated script,
Sleep,500
Reload
}
Return
;Search the array for the remotekey
DoKey(Remotekey)
{
global
;Get active Title
WinGetClass,ActClass,A
;WinGetActiveTitle, ActTitle
;msgbox %ActTitle%
loop, %KeyArray0%
{
KeyofArray := KeyArray%a_index%
;if key is the wrong key, try the next entry
if KeyofArray != %Remotekey%
continue
TitleOfArray := AppArray%a_index%
IfnotInString, ActClass, %TitleOfArray%
continue
;We have found the correct key and the correct application. Send the Key
Key2Send := SendArray%a_index%
;msgbox Send "%Key2Send%"
Send %Key2Send%
return
}
}
SendDVDKey(Key)
{
IfWinNotExist , InterVideo WinDVD 7
{
return
}
Winactivate, InterVideo WinDVD 7
Send, %Key%
}
Dez2Hex(Number)
{
format = %A_FormatInteger% ; save original integer format
SetFormat Integer, Hex ; for converting bytes to hex
Number += 0
SetFormat Integer, %format% ; restore original format
StringTrimLeft, Number, Number, 2
Stringlen := StrLen(Number)
if Stringlen < 2
Number = 0%Number%
return Number
}
ReadIni()
{
global
IfNotExist, .\myremotekeys.ini
{
MsgBox, Inifile myremotekeys.ini not found in current folder
ExitApp , 2
}
IniRead, Counter, .\filiep.ini, RemoteControl, Entrycount
KeyArray0 := Counter
AppArray0 := Counter
SendArray0 := Counter
loop, %Counter%
{
IniRead, IniLine, .\filiep.ini, RemoteControl, %a_index%
StringSplit, OutputArray, IniLine , `;
KeyArray%a_index% := OutputArray1
AppArray%a_index% := OutputArray2
SendArray%a_index% := OutputArray3
}
}
ExtractInteger(ByRef pSource, pOffset = 0, ****igned = false, pSize = 4)
; pSource is a string (buffer) whose memory area contains a raw/binary integer at pOffset.
; The caller should pass true for pSigned to interpret the result as signed vs. unsigned.
; pSize is the size of PSource's integer in bytes (e.g. 4 bytes for a DWORD or Int).
; pSource must be ByRef to avoid corruption during the formal-to-actual copying process
; (since pSource might contain valid data beyond its first binary zero).
{
SourceAddress := &pSource + pOffset ; Get address and apply the caller's offset.
result := 0 ; Init prior to accumulation in the loop.
Loop %pSize% ; For each byte in the integer:
{
result := result | (*SourceAddress << 8 * (A_Index - 1)) ; Build the integer from its bytes.
SourceAddress += 1 ; Move on to the next byte.
}
if (!****igned OR pSize > 4 OR result < 0x80000000)
return result ; Signed vs. unsigned doesn't matter in these cases.
; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
return -(0xFFFFFFFF - result + 1)
}
return
--------------------------------------
Einde van de AHK file
Nu heb je nog een INI file nodig met de meeste commando's die moeten uitgevoerd worden.
Ik gebruik de INI file voor bijna alles.
Echter, voor sommige toetsen heb ik problemen met het uitlezen van de codes, bijvoorbeeld de ENTER toets.
Van zodra ik die indruk, wordt ENTER doorgestuurd, in plaats van dat ik te zien krijg welke getalcodes door de afstandsbediening doorgestuurd worden.
Deze INI file gebruik ik momenteel (wordt als MYHOTKEYS.INI opgeroepen in de vorige AHK file)
--------------------------------------------------------------------------------------------------
[RemoteControl]
Entrycount=15
1=Red;eHome Render Window;^+z
2=Green;eHome Render Window;^+c
3=Yellow;eHome Render Window;^a
4=Blue;eHome Render Window;^o{Up}{Up}{Enter}
5=Red;MediaPlayerClassicW;w
6=Green;MediaPlayerClassicW;{ENTER} !v {UP 3} {RIGHT} {UP 5} {ENTER} {ENTER}
7=Yellow;MediaPlayerClassicW;{ENTER} !v {UP 3} {RIGHT} {UP 4} {ENTER} {ENTER}
8=Blue;MediaPlayerClassicW;{ENTER} !v {UP 3} {RIGHT} {UP 3} {ENTER} {ENTER}
9=Play;MediaPlayerClassicW;{VKFA}
10=Pause;MediaPlayerClassicW;{SPACE}
11=Rewind;MediaPlayerClassicW;!^+{F1}
12=FFwd;MediaPlayerClassicW;!^+{F2}
13=Chapterback;MediaPlayerClassicW;^{LEFT}
14=Chapterfwd;MediaPlayerClassicW;^{RIGHT}
15=Info;#32770;{Tab}
Nu moet je nog enkele toetsen hertoewijzen in Media Player Classic opdat ze zouden overeenkomen met de toetsen die gebruikt worden in de INI file.
Als je dat doet moet je alle mappings hebben zoals ik ze heb.
In Media Player Classic gebruik ik bijv. de cijfertoetsen om in en uit te zoomen en het beeld te rekken, de kleurtoetsen gebruik ik voor ondertiteling en 3 verschillende zoom modes.
Merk op dat de getallen die je in de AK file vindt kunnen anders zijn op uw afstandsbediening.
Als het niet werkt, moet je de instructies op de site volgen om de juiste codes te achterhalen, en kun je het opnieuw naar wens instellen.
In principe kun je die DLL met om het even welke USB afstandsbediening gebruiken.
En vanzelfsprekend kun je het script naar wens veranderen, idem ditto voor wat aan welke toets toegekend wordt.
Autohotkey bevat een hele scripttaal waar toetsenbord en muismacro's mee mogelijk zijn.