Home
Blogs
Forums
Files


Welcome to The Green Button          Sign in | Join | Help

How to reprogram ANY button on your remote

Last post 07-30-2008, 1:07 AM by morberg. 10 replies.
Sort Posts: Previous Next
  •  09-06-2007, 1:15 AM 206986

    • boulder2 is not online. Last active: 11-08-2008, 4:01 AM boulder2
    • Top 500 Contributor
    • Joined on 05-20-2007
    • Belgium, Europe (PAL territory)
    • Member

    How to reprogram ANY button on your remote

    I already discovered Autohotkey a while ago, then Micha 's DLL, and after playing around with it, I can reprogram almost any button to the function of choice.
    Finally, I am able to use the coloured buttons for something useful, or use the remote when navigating in Media Player Classic.

    Here is the script I am currently using.
    I still want to improve it, especially for Media Player Classic, when I have some time, I want to get the FFWD and REWD buttons to act more like they do in MediaCenter.
    Got some help from Micha, he made the system with the INI file.
    There are 3 parts to using it :
    You 'll need to download the DLL from http://www.autohotkey.net/~Micha/HIDsupport/Autohotkey.html
    Now you need to save the lines below as an AHK file (for example : 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

    --------------------------------------
    End of the AHK file.


    Now you still need an INI file for most commands.
    I use the INI file for almost anything.
    However, I have some problems with keys that I cannot read from the utility, such as the ENTER key.
    As soon as I press it, ENTER is passed on, instead of showing me the numbers that are sent by the remote.

    Here is the INI file I 'm currently using : (referred to as myhotkeys.ini in the 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}

    Now you still have to remap some keys in Media Player Classic so they will correspond with the keys used in the INI file.

    If you do that you should get most keys as I used them.
    For example, I use the number keys in Media Player Classic to zoom and stretch the image when necessary, and the coloured buttons for the different zoom modes.

    PAL territory, using analogue cable Hauppauge PVR-350 and Hauppauge PVR-250, living in Belgium, Europe
    http://www.extrabuttons.net
  •  09-06-2007, 3:05 PM 207115 in reply to 206986

    Re: How to reprogram ANY button on your remote

    nice work

    there's a few things I've wanted to accomplish and I think this'll make it viable
  •  01-14-2008, 8:40 PM 236126 in reply to 206986

    Re: How to reprogram ANY button on your remote

    I hate to post a stupid question, but anyone seen this error?  Any advice welcome. I checked and see 2 references to this same string so I'm guessing it was set that way on purpose.

    Error at line 284.

    The following variable name contains an illegal character:

    "****igned"

    The program will exit.

    -Newbie

  •  02-15-2008, 1:36 PM 243667 in reply to 236126

    Re: How to reprogram ANY button on your remote

    I bet that the **** is from the forum thinking somebody said a bad word as part of that string.

    I can't think of what it could be offhand, though.

    Main Media Center
    ---------------------------
    Vista Ultimate SP1 TV Pack
    BioStar TP43D2-A7 Mobo
    2.2GHZ Core2 Duo
    3GB Ram
    300GB Drive Space
    Hauppauge HVR-1600
    Hauppauge PVR-150
    Gigabit Ethernet
    GeForce 7300

  •  02-15-2008, 1:44 PM 243669 in reply to 243667

    Re: How to reprogram ANY button on your remote

    Got it!

    After some searching, it seems that the forum software is killing the four-letter word that starts with the letter "P" and rhymes with "miss"

    If you replace the asterisks with p-i-s-s (but remove the dashes) the script should work.

    Main Media Center
    ---------------------------
    Vista Ultimate SP1 TV Pack
    BioStar TP43D2-A7 Mobo
    2.2GHZ Core2 Duo
    3GB Ram
    300GB Drive Space
    Hauppauge HVR-1600
    Hauppauge PVR-150
    Gigabit Ethernet
    GeForce 7300

  •  03-11-2008, 2:25 PM 249485 in reply to 243669

    • boulder2 is not online. Last active: 11-08-2008, 4:01 AM boulder2
    • Top 500 Contributor
    • Joined on 05-20-2007
    • Belgium, Europe (PAL territory)
    • Member

    Re: How to reprogram ANY button on your remote

    Oh, I just pasted the code in the forum, never thinking something might get censured.
    Puritanism eh :-)

    PAL territory, using analogue cable Hauppauge PVR-350 and Hauppauge PVR-250, living in Belgium, Europe
    http://www.extrabuttons.net
  •  03-26-2008, 12:42 PM 252626 in reply to 249485

    Re: How to reprogram ANY button on your remote

    Is there any way to have this program map a remote buttons, say 1,2,3,4, and 5 to different star ratings? Or can in only be used to map remote buttons to keyboard keys?
  •  03-26-2008, 1:07 PM 252636 in reply to 252626

    • boulder2 is not online. Last active: 11-08-2008, 4:01 AM boulder2
    • Top 500 Contributor
    • Joined on 05-20-2007
    • Belgium, Europe (PAL territory)
    • Member

    Re: How to reprogram ANY button on your remote

    What do you mean by that ?
    Do you mean to say that if you press the "1" button, Mediacenter will search the guide for upcoming films with a single star rating ?
    If you can do this by a series of keyboard commands, yes you could do that.
    If you mean that the function does not exist in Mediacenter, of course you can't.
    We are reprogramming buttons here, not adding functions to the Mediacenter code.

    PAL territory, using analogue cable Hauppauge PVR-350 and Hauppauge PVR-250, living in Belgium, Europe
    http://www.extrabuttons.net
  •  03-26-2008, 2:12 PM 252662 in reply to 252636

    Re: How to reprogram ANY button on your remote

    Sorry, I guess I was pretty vague, I meant is it possible to program the buttons to change a songs star rating.
  •  04-02-2008, 1:27 PM 254421 in reply to 252662

    • boulder2 is not online. Last active: 11-08-2008, 4:01 AM boulder2
    • Top 500 Contributor
    • Joined on 05-20-2007
    • Belgium, Europe (PAL territory)
    • Member

    Re: How to reprogram ANY button on your remote

    I 'm always busy with video, so I have no idea how you would do that, but if there is a certain number of keystrokes you use in a set order that accomplishes this, you can always reprogram the button so that it sends them at a keystroke.
    If not, then no, it will probably not work.

    PAL territory, using analogue cable Hauppauge PVR-350 and Hauppauge PVR-250, living in Belgium, Europe
    http://www.extrabuttons.net
  •  07-30-2008, 1:07 AM 279106 in reply to 206986

    Re: How to reprogram ANY button on your remote

    boulder2:

    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
    }
    }

    Shouldn't the two occurences of .\filiep.ini be replaced with .\myremotekeys.ini ?

    Blog at http://niklasmorberg.blogspot.com
View as RSS news feed in XML
About TGB | Advertise | Link To Us | Donate | Terms Of Use | Privacy Policy
© 2003-2007 The Green Button, Inc. - All Rights Reserved