Win My solution - Using MCE remote and video streaming web-sites
#1
I hope I am posting in the correct forum, please forgive me if I've got the etiquette wrong. Sorry also for the long post.


The TL : DR: This is my autohotkey script which detects when Chrome is launched from Kodi (using probably AdvancedLauncher) and then allows mouse control with the MCE remote. The script is a mash-up of three separate scripts from people who have far more idea what they are doing than me.[


This is my solution to launching websites from Kodi and controlling them with the remote. This is mainly for video streaming sites, like BBC iPlayer, Amazon Prime, Netflix etc.

I just wanted to share my solution to a problem I was having, in the hope that other people may find it useful. I thought it was time to share, given I hardly post and mostly lurk.

I mostly use Kodi on the sofa with a windows MCE remote.

I have spent a few weeks failing to get video streaming sites working the way I wanted

I have tried a few add-ons and I wanted something that was more universal.

I know there are very good options, like Romans I XVI Amazon Prime + Chrome Launcher, but wanted to try and do something myself.

This is the result after a weekend and a few evenings of tinkering.

It is an AutoHotkey script, that combines three different scripts which I have mixed together and amended.

I am a complete novice at any form of scripting, in fact, I've never done any before last weekend, so please be kind. I am sure it is riddled with mistakes, but it seems to work. I know that it is very basic, but I think it is useful.

It does the following:

1. When a chrome website is launched from within Kodi, the MCE remote instead controls the mouse and the mouse cursor is replaced with a larger version than can easily be seen from the sofa.

2. Certain of the MCE buttons are altered to be more useful in those websites (play is 'double click', pause is 'space', stop is 'escape')

3. When the Green Button is pressed, Chrome is closed, you are returned to Kodi, the cursor reverts to its original state and the MCE remote again reverts to not controlling the mouse.



If there is any credit to be had, it is not mine, but the original authors of the three scripts (which I am sure I have probably butchered).

They are:
1. elitegamer360 - Green Button and MCE support
2. Serenity - Changing the cursor
3. Deguix - Using keyboard as mouse


How this works:

- You need to get your MCE remote running as per elitegamer360's instructions here. This changes the registry so that the MCE remote buttons are mapped to the correct keys. Importantly, the green button becomes Ctrl-Alt-Enter.

- If you follow his instructions you will see that you are required to install AutoHotkey.

- elitegamer360 provides his custom AutoHotkey scripts here. I have taken it and amended it, adding bits and removing bits I personally didn't need (eg the switch to turn auto-focus of the window on and off etc). I think by default elitegamer's installer puts the autohotkey script in the startup folder. I simply removed his and replaced it with mine - which therefore means my script autoloads on windows booting up.

- There is a cursor file (cursor.cur) which you must place in the 'userdata' folder of Kodi (in windows 64 it should be C:\Users\[username]\AppData\Roaming\Kodi\userdata). The location of the file can be changed in the script. You can also turn off the cursor change if you wish.

- I created Chrome .lnk shortcuts to the websites I wanted, and amended the 'target' field in properties so that they would all open in full-screen kiosk mode.

- Use Advanced Launcher to open the links.

- When Chrome sites are opened, the mouse cursor can be controlled by the arrow keys on the remote. 'OK' is single click.

- On a lot of these sites the Flash video or Silverlight (with Amazon) plugins have limited keyboard shortcuts. Double click tends to toggle between full screen views, so the play button is now mapped to double-click, to easily change to full screen. The spacebar tends to be pause, and is therefore mapped to pause and stop is 'escape'. The back button is mapped to 'browser-back'.


The script is:
Code:
;     Autohotkey script - http://www.autohotkey.com/
;
;     script created by ben79 by combining and changing scripts by other people
;     all the hard work was done by them, I have just put bits of their scripts together
;     all the credit must therefore go to
;     elitegamer360 at http://xbmccustomregis.sourceforge.net/credits.html
;     Serenity at http://www.autohotkey.com/board/topic/32608-changing-the-system-cursor/
;     and
;     deguix at http://www.autohotkey.com/docs/scripts/NumpadMouse.htm
;

#SingleInstance force
#MaxHotkeysPerInterval 500
#UseHook
#InstallKeybdHook
#Persistent
#NoEnv

SendMode Input



; User variables - for you to change as needed

MouseSpeed = 2                                      ;Change initial speed of mouse pointer
MouseAccelerationSpeed = 8                            ;Change acceleration rate of mouse pointer
MouseMaxSpeed = 25                                    ;Set maximum speed of mouse pointer

Cursor = %A_AppData%\Kodi\userdata\cursor.cur       ;Set location of the cursor file - by default the userdata folder for Kodi

ChangeCursor = 1                                    ;Do you want the cursor to change when controlled by the remote?  1 for yes, or 0 for no.








; Program variables - DO NOT CHANGE

Temp = 0
Temp2 = 0

MouseRotationAnglePart = %MouseRotationAngle%
MouseRotationAnglePart /= 45

MouseCurrentAccelerationSpeed = 0
MouseCurrentSpeed = %MouseSpeed%

MouseWheelCurrentAccelerationSpeed = 0
MouseWheelCurrentSpeed = %MouseSpeed%

SetKeyDelay, -1
SetMouseDelay, -1

Hotkey, *Enter, ButtonLeftClick
Hotkey, *Up, ButtonUp
Hotkey, *Down, ButtonDown
Hotkey, *Left, ButtonLeft
Hotkey, *Right, ButtonRight
Hotkey, ^p, SpaceBar
Hotkey, *Backspace, WebPageBack
Hotkey, ^+s, EscapeButton
Hotkey, ^+p, DoubleClick



Hotkey, *Enter, off
Hotkey, *Up, off
Hotkey, *Down, off
Hotkey, *Left, off
Hotkey, *Right, off
Hotkey, ^p, off
Hotkey, *Backspace, off
Hotkey, ^+s, off
Hotkey, ^+p, off
    
    
ChromeState = 0                                                  ;Sets a timer to constantly check if Chrome is running
SetTimer, CheckChrome, 250
return

CheckChrome:
IfWinExist, ahk_class Chrome_WidgetWin_1                         ;If Chrome is running...
{
    If WinExist("Kodi")                                          ;And if Kodi is running...
    {


        If ChromeState = 0                                       ;If first time that Chrome has been seen to be on(ie was previously off)
        {
            If ChangeCursor = 1                                  ;And if User wants the cursor to change
            {
                cx := 100, cy := 100
               {
               SystemCursors = 32512IDC_ARROW,32513IDC_IBEAM,32514IDC_WAIT,32515IDC_CROSS
               ,32516IDC_UPARROW,32640IDC_SIZE,32641IDC_ICON,32642IDC_SIZENWSE
               ,32643IDC_SIZENESW,32644IDC_SIZEWE,32645IDC_SIZENS,32646IDC_SIZEALL
               ,32648IDC_NO,32649IDC_HAND,32650IDC_APPSTARTING,32651IDC_HELP
  
                   Loop, Parse, SystemCursors, `,
                   {
                   Type = FileCursor
                   %Type%%A_Index% := DllCall( "LoadImage", UInt,0, Str,Cursor, UInt,0x2, Int,cx, Int,cy, UInt,0x10 )
                   DllCall( "SetSystemCursor", Uint,%Type%%A_Index%, Int,SubStr( A_Loopfield, 1, 5 ) )  
                                                                
                                                                 ;All system cursors replaced with new larger cursor file
                   }
               }
            }
        
        
        Hotkey, *Enter, on                                       ;Keyboard mouse control switched ON
        Hotkey, *Up, on
        Hotkey, *Down, on
        Hotkey, *Left, on
        Hotkey, *Right, on
        Hotkey, ^p, on
        Hotkey, *Backspace, on
        Hotkey, ^+s, on
        Hotkey, ^+p, on        
      
         ChromeState = 1                                            ;Chrome variable changed to 1 (ie Chrome now running)
        }
    }
}

IfWinNotExist, ahk_class Chrome_WidgetWin_1                     ;If Chrome is NOT running

{
    If ChromeState = 1                                          ;And if Chrome was previously running immediately prior to checking
    {
    Hotkey, *Enter, off                                         ;Keyboard control of mouse switched OFF
    Hotkey, *Up, off
    Hotkey, *Down, off
    Hotkey, *Left, off
    Hotkey, *Right, off
    Hotkey, ^p, off
    Hotkey, *Backspace, off
    Hotkey, ^+s, off
    Hotkey, ^+p, off
    
    SPI_SETCURSORS := 0x57                                      ;System cursors set back to defaults
    DllCall( "SystemParametersInfo", UInt,SPI_SETCURSORS, UInt,0, UInt,0, UInt,0 )
            
    ChromeState = 0                                             ;Chrome variable changed to 0 (ie Chrome now not running)
    }
}

Return






; GREEN BUTTON SCRIPT - Taken from elitegamer360 at http://xbmccustomregis.sourceforge.net/credits.html




^!Enter::                                           ;Ctrl-Alt-Enter is the shortcut to start Kodi using the Big Green Start Button.

IfWinNotExist Kodi.exe                             ;If Kodi is not running....
VarSetCapacity(si,44)
DllCall("GetNativeSystemInfo", "uint", &si)

if ErrorLevel {
MsgBox Windows XP or later required.
ExitApp
}
ARM := NumGet(si,0,"ushort")
run % ARM=0 ? "C:\Program Files\Kodi\Kodi.exe" : ARM=9 ? "C:\Program Files (x86)\Kodi\Kodi.exe" : ARM=6 ? "IA64" : "Unknown System"

        If (ARM = 0)
        {
            32or64 := "32bit"
        }
        If (ARM = 9)
        {
            32or64 := "64bit"
        }
        If (ARM = 6)
        {
            32or64 := "Unknown System"
        }

    WinActivate, Kodi
       WinMaximize, Kodi
    
    IfWinActive Kodi ahk_class Kodi ; Kodi detection for Kodi/GSB Home Screen action.
    WinGet, Style, Style, ahk_class Kodi
    if (Style & 0xC00000)  ;0xC00000 is WS_CAPTION, meaning window has a title bar.
    {
    Send {VKDC}  ;Maximize Kodi to fullscreen mode if its in a window mode.
    }
    WinMaximize ;Maximize Kodi if Windowed.
    send ^h ; if Kodi is Active (GSB Home Jump will activate)
        
    
ChromeOpen := 1                                             ;On pressing GREEN BUTTON all chrome windows close
While ChromeOpen = 1                                        ;A loop, checks to see if Chrome running, if so closes window, if not, loop ends
IfWinExist, ahk_class Chrome_WidgetWin_1
{    
WinClose
}
else
{
ChromeOpen :=0
}

Return
    
    


    
; KEYBOARD MOUSE CONTROL SCRIPT





;Button Set up

ButtonLeftClick:
Send {Click}
return

WebPageBack:
Send {Browser_Back}
return

SpaceBar:
Send {Space}
return

EscapeButton:
Send {Escape}
return

DoubleClick:
Send {Click 2}
return





;Mouse movement support



ButtonUp:
ButtonDown:
ButtonLeft:
ButtonRight:
ButtonUpLeft:
ButtonUpRight:
ButtonDownLeft:
ButtonDownRight:
If Button <> 0
{
    IfNotInString, A_ThisHotkey, %Button%
    {
        MouseCurrentAccelerationSpeed = 0
        MouseCurrentSpeed = %MouseSpeed%
    }
}
StringReplace, Button, A_ThisHotkey, *

ButtonAccelerationStart:
If MouseAccelerationSpeed >= 1
{
    If MouseMaxSpeed > %MouseCurrentSpeed%
    {
        Temp = 0.001
        Temp *= %MouseAccelerationSpeed%
        MouseCurrentAccelerationSpeed += %Temp%
        MouseCurrentSpeed += %MouseCurrentAccelerationSpeed%
    }
}

;MouseRotationAngle convertion to speed of button direction
{
    MouseCurrentSpeedToDirection = %MouseRotationAngle%
    MouseCurrentSpeedToDirection /= 90.0
    Temp = %MouseCurrentSpeedToDirection%

    if Temp >= 0
    {
        if Temp < 1
        {
            MouseCurrentSpeedToDirection = 1
            MouseCurrentSpeedToDirection -= %Temp%
            Goto EndMouseCurrentSpeedToDirectionCalculation
        }
    }
    if Temp >= 1
    {
        if Temp < 2
        {
            MouseCurrentSpeedToDirection = 0
            Temp -= 1
            MouseCurrentSpeedToDirection -= %Temp%
            Goto EndMouseCurrentSpeedToDirectionCalculation
        }
    }
    if Temp >= 2
    {
        if Temp < 3
        {
            MouseCurrentSpeedToDirection = -1
            Temp -= 2
            MouseCurrentSpeedToDirection += %Temp%
            Goto EndMouseCurrentSpeedToDirectionCalculation
        }
    }
    if Temp >= 3
    {
        if Temp < 4
        {
            MouseCurrentSpeedToDirection = 0
            Temp -= 3
            MouseCurrentSpeedToDirection += %Temp%
            Goto EndMouseCurrentSpeedToDirectionCalculation
        }
    }
}
EndMouseCurrentSpeedToDirectionCalculation:

;MouseRotationAngle convertion to speed of 90 degrees to right
{
    MouseCurrentSpeedToSide = %MouseRotationAngle%
    MouseCurrentSpeedToSide /= 90.0
    Temp = %MouseCurrentSpeedToSide%
    Transform, Temp, mod, %Temp%, 4

    if Temp >= 0
    {
        if Temp < 1
        {
            MouseCurrentSpeedToSide = 0
            MouseCurrentSpeedToSide += %Temp%
            Goto EndMouseCurrentSpeedToSideCalculation
        }
    }
    if Temp >= 1
    {
        if Temp < 2
        {
            MouseCurrentSpeedToSide = 1
            Temp -= 1
            MouseCurrentSpeedToSide -= %Temp%
            Goto EndMouseCurrentSpeedToSideCalculation
        }
    }
    if Temp >= 2
    {
        if Temp < 3
        {
            MouseCurrentSpeedToSide = 0
            Temp -= 2
            MouseCurrentSpeedToSide -= %Temp%
            Goto EndMouseCurrentSpeedToSideCalculation
        }
    }
    if Temp >= 3
    {
        if Temp < 4
        {
            MouseCurrentSpeedToSide = -1
            Temp -= 3
            MouseCurrentSpeedToSide += %Temp%
            Goto EndMouseCurrentSpeedToSideCalculation
        }
    }
}
EndMouseCurrentSpeedToSideCalculation:

MouseCurrentSpeedToDirection *= %MouseCurrentSpeed%
MouseCurrentSpeedToSide *= %MouseCurrentSpeed%

Temp = %MouseRotationAnglePart%
Transform, Temp, Mod, %Temp%, 2

If Button = Up
{
    if Temp = 1
    {
        MouseCurrentSpeedToSide *= 2
        MouseCurrentSpeedToDirection *= 2
    }

    MouseCurrentSpeedToDirection *= -1
    MouseMove, %MouseCurrentSpeedToSide%, %MouseCurrentSpeedToDirection%, 0, R
}
else if Button = Down
{
    if Temp = 1
    {
        MouseCurrentSpeedToSide *= 2
        MouseCurrentSpeedToDirection *= 2
    }

    MouseCurrentSpeedToSide *= -1
    MouseMove, %MouseCurrentSpeedToSide%, %MouseCurrentSpeedToDirection%, 0, R
}
else if Button = Left
{
    if Temp = 1
    {
        MouseCurrentSpeedToSide *= 2
        MouseCurrentSpeedToDirection *= 2
    }

    MouseCurrentSpeedToSide *= -1
    MouseCurrentSpeedToDirection *= -1

    MouseMove, %MouseCurrentSpeedToDirection%, %MouseCurrentSpeedToSide%, 0, R
}
else if Button = Right
{
    if Temp = 1
    {
        MouseCurrentSpeedToSide *= 2
        MouseCurrentSpeedToDirection *= 2
    }

    MouseMove, %MouseCurrentSpeedToDirection%, %MouseCurrentSpeedToSide%, 0, R
}
else if Button = NumPadHome
{
    Temp = %MouseCurrentSpeedToDirection%
    Temp -= %MouseCurrentSpeedToSide%
    Temp *= -1
    Temp2 = %MouseCurrentSpeedToDirection%
    Temp2 += %MouseCurrentSpeedToSide%
    Temp2 *= -1
    MouseMove, %Temp%, %Temp2%, 0, R
}
else if Button = NumPadPgUp
{
    Temp = %MouseCurrentSpeedToDirection%
    Temp += %MouseCurrentSpeedToSide%
    Temp2 = %MouseCurrentSpeedToDirection%
    Temp2 -= %MouseCurrentSpeedToSide%
    Temp2 *= -1
    MouseMove, %Temp%, %Temp2%, 0, R
}
else if Button = NumPadEnd
{
    Temp = %MouseCurrentSpeedToDirection%
    Temp += %MouseCurrentSpeedToSide%
    Temp *= -1
    Temp2 = %MouseCurrentSpeedToDirection%
    Temp2 -= %MouseCurrentSpeedToSide%
    MouseMove, %Temp%, %Temp2%, 0, R
}
else if Button = NumPadPgDn
{
    Temp = %MouseCurrentSpeedToDirection%
    Temp -= %MouseCurrentSpeedToSide%
    Temp2 *= -1
    Temp2 = %MouseCurrentSpeedToDirection%
    Temp2 += %MouseCurrentSpeedToSide%
    MouseMove, %Temp%, %Temp2%, 0, R
}

SetTimer, ButtonAccelerationEnd, 10
return

ButtonAccelerationEnd:
GetKeyState, kstate, %Button%, P
if kstate = D
    Goto ButtonAccelerationStart

SetTimer, ButtonAccelerationEnd, on
MouseCurrentAccelerationSpeed = 0
MouseCurrentSpeed = %MouseSpeed%
Button = 0
return




RemoveToolTip:
SetTimer, RemoveToolTip, on
ToolTip
return


Files

- My AutoHotkey script is here

- This is the cursor file


Next Steps

I would love to learn how to create an onscreen keyboard for text input (much like the Kodi virtual keyboard) that can be controlled with the remote. I think this is far beyond my capacity though...

Hope people find this useful,

Thanks
Reply
#2
*bump*

Is this useful to anyone...?
Reply
#3
Good work. As for the keyboard thing, why not use the windows on-screen keyboard? You can map one of the remote control buttons to start the keyboard.
Reply
#4
Already tried that.

The problem with using windows in-built osk.exe is that there is no solution (that I can see) that allows you to use the cursor keys to select letters (as per the Kodi osk). It requires the use of the mouse cursor to select letters. However, using the remote control as the mouse is too cumbersome for typing anything more than a few letters.

If there were a way to use the cursor keys to navigate the keyboard in osk, that would be perfect, but I can't find it.
Reply
#5
May be there are third party keyboards with the functionality you are looking for. You can also create one using visual studio or other programming languages.
Reply
#6
This works great. thanks for your efforts. Its exactly what I was after.
I do however have a problem with 1 site. youtube works a little different. There is no way to move the screen left to right or up and down. This kinda renders the app useless on this site. But for whatever reason firefox works perfect the way it naturally controls the page with the exception of closing the page and returning to kodi. Can this script be tweaked to provide the green button close on firefox as well?
Reply
#7
Wow, I will give this a try, as I also was looking for a way just for these issues. I`ll be back with impressions in a couple of days. Anyway, tnx for the special work!
Reply

Logout Mark Read Team Forum Stats Members Help
My solution - Using MCE remote and video streaming web-sites0