MCE Controller Plugin for Keyboard and Mouse Interface

@Shuggy a second thing popped into my head as well (the thoughts do eventually work their way up out of the depths)… I tried the 2-finger tap on my iPad and it also did not work for a right-click, which brought up a vague memory that I thought I had discussed years ago with @bill that this was a THR limitation, but after some searching I couldn’t find it anywhere, so who knows. Regardless, I believe THR’s WebBrowser control (maybe THR itself?) does not support multi-touch. You could test this by bringing up a web browser app on your device and going to: http://IP-address-of-your-HTPC:6224/index.html and that should bring up the MouseHelper interface in your web browser, which most likely does support multi-touch, so you could experiment with that. It’s not real practical for interacting with your HTPC, but I thought it might be useful to know.

@hotelfoxtrotnovember Yes! I just got around to playing with the repeat button and realised that the interval was quite high (it doesn’t sound that much, but you’re right it’s a long time on a button press). Down at 50/60ms it works a treat. My arrow keys work perfectly now - they act pretty much like a physical keyboard and I can traverse documents, etc easily. :+1:

I have tried this before on both devices but just for sanity I tested it again (Android mobile and 10" tablet). Even using the web browser (index.html) I get absolutely no response with the double-finger tap, so you are correct - it looks like there is no support for that in the WebBrowser control.
Thanks for looking into it and confirming the behaviour (or lack of).

On the subject of the index.html…
I played around with the settings/options at the top of the file to customise the touchpad a little. One issue is that even on the larger tablet screen, the scrollpad by default is very sensitive! You just have to move your finger a hair’s width and you have scrolled a page. Do you see similar sensitivity on your ipad?

I have managed to find a workaround for web browsers by installing a scroll addon/extension and vastly reducing the scroll step size. However, this obviously does not apply to windows explorer and other apps.

Is it correct that the ‘SCROLL_INCREMENT’ in the index.html only obeys whole numbers? I tried reducing this to 0.2, 0.3, etc but the scrollpad stops working completely unless set to a whole number. I was kind of hoping it would be some sort of multiplier so I could reduce the scroll speed.
Is this to be expected and if so, is there any way of reducing the scroll speed?

Thanks again,
Shuggs

EDIT: By contrast I changed the ‘MOUSE_MOVE_SCALE’ and that works really well (I have it set around 2.5.)

I do find the scrollpad a little more sensitive than I’d like, but it’s generally been sufficiently workable for me. You are correct about the SCROLL_INCREMENT being an integer. That is passed through to MCEC as a mouse:vs command, which takes the SCROLL_INCREMENT as the parameter corresponding to “the amount to scroll in clicks”. I interpret “clicks” in this context to be clicks of the scroll wheel in rotation. So 1 would be the minimum you can do, unfortunately.

That said, in Windows you can set how many lines to scroll each time the wheel is turned (Settings → Devices → Mouse). Also, you might want to play with the SCROLL_THRESHOLD parameter in the index.html, as that is how far your finger has to travel before it registers a scroll event. That would also make it a little less sensitive from the standpoint of scroll events not firing as often per distance traveled in the scrollpad.

If you find a value for SCROLL_THRESHOLD you like, please let me know and I’ll try it out too. Maybe the MouseHelper just needs an updated default value to make it a little more friendly.

1 Like

I’d been playing around with the SCROLL_THRESHOLD parameter as well - this yielded slight results. But I’d completely forgotten about the Windows setting on scroll lines. Good shout! So I’ve dropped this from the default of 3 lines to 1 line (minimum) in the Win10 settings. The scrollpad is still not perfect, but it is much more stable and easier to control now. :+1:

I’m getting the remaining building blocks in place for PC control before I start looking into a design & UI layout. The power and flexibility of all this blows my mind. The fact that I’m controlling the devices through ethernet LAN too - which means the response is instant and I can be as far away as I like and not worry about IR/Bluetooth dropouts. :sunglasses:

I agree completely about the Ethernet/IP control – I vowed I would never buy another non-IP controllable device again, ended up experimenting with the Nvidia Shield (the latest one, which removed IP control and can only be controlled over IR), and finally had enough after a few months to dust off an old computer and build my current HTPC :slight_smile:

One word of warning–MCEC seems to have some limitations with some of Window’s security features (UAC is the most notable) and when one of those boxes and/or a window requiring Admin rights pops up, Windows stops responding to MCEC's virtual keyboard/mouse inputs. It doesn’t happen much, but it is very frustrating when it does, because the only solution I’ve found is to plug a keyboard/mouse into the computer to try to clear it. If you (or anyone else!) knows how to get around those issues, I would love to know!

Sure do! I set my new HTPC up with full admin access from the get-go (with a bespoke debloated version of Win10.) I’ve also got 2 older PCs running in this fashion and I’ve never had any issues with those.

The key is to only run a single account and make sure it is an Administrator. Then you can disable the Admin approval, stopping any popups and notifications. The extra win here is even when you change things like the display fps, you do not get popups asking you to revert changes, etc - it just changes the display.

**Note: This is for Windows 10 only - I do not know if this works the same in Win7/Win11, etc.


1. So the first thing is to check your user account is an Administrator. Follow the image instructions to check your account status…

If you already have an Administrator account, then jump down to step 2 below. If not, then this is how you change your account type…

  • Open Control Panel
  • Under the User Accounts section, click Change account type
  • Select your account
  • Click the Change the account type option
  • Select Administrator
  • Click the Change Account Type button
  • Restart you PC (or log out) for the account to be updated

2. Now we need to turn off the Admin approvals for the account. This is very simple…

  • Click the Start menu
  • Type in "group policy"
  • Click Edit Group Policy in the Start menu results
  • In the Group Policy window, navigate to: Computer Configuration > Windows Settings > Security Settings > Local Policies > Security Options

  • Scroll down to the bottom and make sure the highlighted Admin Approval option is Disabled (to change it, right-click > properties and check the ‘Disabled’ option)
  • Apply any changes and close the Group Policy window
  • Restart your PC for the changes to take effect

After restart you should test running some of the apps, etc that required admin approval to see whether they still generate pop-ups and (hopefully) they have been disabled correctly.

Let me know if you have any problems or it doesn’t work - there’s a possibility I changed some other settings to do this and I’ve forgotten some of it!

Shuggs

P.S: I recommend only using the HTPC for your media purposes and do any sensitive work/finances, etc on other devices. That’s just me though - I’m paranoid like that. :upside_down_face:

1 Like

Thanks for the awesome write-up on this, @Shuggy! I have done some of those things, but I don’t think all of them, so hopefully that will take care of the few random annoyances I still encounter!

1 Like

No problem! :+1:

I wonder if you can help with another THR/MCEC issue I’m having? The “PowerOn” command refuses to power-on / wake-up my HTPC (the “PowerOff” command works fine.)

All relevant WOL settings are enabled on the HTPC (BIOS, NIC adapter, Power management, magic packets, etc.)

If I run a simple WOL command from any another PC in the network, the HTPC always turns on.
If I use my FLIRC USB dongle (set with a simple ‘wake’ button) it always wakes up the HTPC via my Logitech Harmony remote (using a mapped button).

Strangely, if I run a ‘Startup Activity’ from a THR button (start PC > start TV > change input > launch a youtube browser), the HTPC will not power up. However, if I then manually press the power button, a short time after it comes out of standby, the remainder of the activity occurs (launching the youtube browser.)

I’m assuming this is something to do with the power-off/suspend state of the HTPC (so MCEC is not able to receive inputs.) When a PC is sent the ‘standby’ command from the THR plugin which power state is the PC going into (S1-S5)?

Any ideas what might be the issue here? It’s frustrating because I’m pretty much fishing in the dark at this point.

Thanks!

I’ll be honest, I had thought that my WoL functionality was working fine but I discovered it might have only been working when the HTPC turned the display off (but hadn’t actually gone to sleep), so I may need to experiment more myself.

What do you use to send the WoL command that works? I recall that some devices need to have the IP address specified in the WoL magic packet and not just the MAC address. Perhaps that is what is going on here? I also recall there are a couple of different port options that are sometimes needed as well. I have a more complicated WoL routine I wrote for another plugin that needed it, but I’ll have to dig up which one it was.

That’s really weird about the delayed set of commands, but I wonder if the HTPC when asleep is still buffering the network data to MCEC and that is why Youtube launches as you’re seeing? Alternatively, perhaps the TCP connection from THR to MCEC to send the commands is trying to send and when the HTPC wakes up, it eventually gets through?

Regarding what power state the standby command triggers, I honestly do not know. The command is built in to MCEC (see MCE Controller Documentation | MCE Controller). I’m guessing S3, but I honestly don’t know.

No problem - I only have S1, S2, S3 and hibernate available on the HTPC so my suspicion was that it was S3 too. I guess it’s irrelevant really - a WOL command should wake any of them up. It’s good to know that yours may not be actually sleeping/waking up too (just for my sanity’s sake) :wink:

It does feel like the commands are stored and repeated once the HTCP does wake up (it takes ~5+ seconds after wake-up for the commands to start executing.)
I’ve tested this theory a little further by running the activity 3 or 4 times before manually waking up the PC with the power button. Sure enough, all of the commands are then executed and I end up with 3 or 4 instances of youtube web browsers.

Waking up the HTPC from any other PC on my network, I send a magic packet using wolcmd. I run a simple batch script as follows…

wolcmd [mac address] [ip address] [subnet mask] [port number]

wolcmd 11:22:33:44:55:66 192.168.1.99 255.255.255.0 9
timeout /t 2
exit

It would be great if you have the time to look into it and hunt down ‘the other WOL’ you had - it might just do the trick.
As always, thanks for your support and helping me out!

I threw together a quick and dirty plugin with the more complex WoL code:
MCEController.plugin - 2023-05-27-TEST.js.txt (20.6 KB)

If this works, I will clean it up a little and add some additional plugin settings. For now, this way you only need to copy/paste the new code in and not worry about any additional plugin setup.

To use it, your Host setting needs to be an IP address. Also, it currently doesn’t use a port by default, but if you want to force it to use port 9 (as your wolcmd takes as a parameter) you need to set the WOLPORT variable up at the top to be "9" (it might work if it’s the number 9, but it is intended that you give it the string).

I haven’t had a chance to test this myself, but wanted to try to keep things moving for you. Please let me know what you discover and/or if you have any questions/problems.

1 Like

Tested by copy-pasting the code from this plugin and replacing my existing one. It works a treat! Thanks very much for quick fixing this - your support is amazing.

FYI, my setup was tested with the WOL port left blank and set to ‘9’ (to mimic the wolcmd wake-up). Both ways it reliably wakes the HTPC up now (tested 20-30 times with various sleep durations). :sunglasses:

It got me thinking on whether there is any way of knowing the power status of the HTPC in THR? (similar to the .Switch property on other devices) Asides being able to provide status feedback for the user, it would also be handy for other reasons (triggering events based on the HTPC on/off states.)

What do you think…is this possible?

Thanks for testing, @Shuggy and I’m glad it worked! I have updated the top post with a more polished version of the plugin. This one adds some additional Settings, so technically I think you need to delete and re-add the plugin in its entirety (otherwise the new Settings don’t get added). The defaults are set based on what you discovered (using the IP address and port 9) because, as far as I know, MCEC only runs on Windows, so those seemed like the best defaults for this plugin.

I tested it out and it seems to work for me as well, but I did rearrange the code a bit since I didn’t like where the WOL stuff was located. It should be cleaner and hopefully I didn’t break anything in the process :slight_smile: As always, please let me know if you have any problems.

Regarding knowing the power status of the HTPC, I think the answer is no. There’s nothing magical about the Switch Attribute–the value for it just gets set based on feedback from the device in the plugins/built-in devices that support it. But if the HTPC is off, there’s no way to query that (you might be able to infer it based on a connection timeout, but that is pretty clunky because THR doesn’t provide reliable timeouts on connection attempts, as I recall, and it takes a long time).

I think some home automation hubs may have a little better support for tracking the state of a PC device (using pings or something), but I’ve never played around with those–I got into THR to control my home theater setup and not for more general home automation. That might be your best avenue, at least for triggering events, I’d think.

All of that said, in other plugins I have added some internal psuedo-power state tracking, just to reduce trying to connect to a device that I don’t know whether it is on yet not, so it avoid some timeout-type behavior which is annoying. That might be possible here, but I’m not sure it really makes sense–there’s no harm in sending WOL when it’s already on, so the assumption is that it is always on, and the internal power state tracking adds some complexity.

1 Like

Yeah, that’s fair enough - it was just a ‘wish list’ kind of thing for completeness. I too am only really interested in controlling my AV setup (and a few lights/cameras) so I want to avoid adding extra devices, controllers and complexity into it all for negligible benefit.

Excellent! Great work :+1:
I’ll give the new version above another test. I was about to edit my post above (before I saw you had replied) because I noticed this morning that the HTPC did not power on with the WOL. :confused:
Even though I did multiple tests with it over the weekend, the longest I left it to test the wakeup was probably half an hour or so. It seems that leaving the unit overnight, the WOL no longer works. No idea what could be happening there - but I’ll try the new version (fully removing the plugin and re-adding it) and maybe that will work.

I’ll give the new version a test overnight and let you know if it powers on or not in the morning. Thanks!

I’m concerned to hear that the WOL didn’t work after an overnight sleep. Not sure what would be the issue there–maybe Windows goes into a deeper power-save mode after some amount of time? I haven’t tested such a scenario myself, but like your prior tests, it did wake up after some shorter-period tests. One thing I did notice is that it takes 10-15 seconds for Windows to wake back up after sending the PowerOff (MCEC standby), which was surprisingly longer than I’d expected. Anxious to hear what you discover.

Just to clarify - I meant that only the first wake-up didn’t work after the overnight sleep. After I had woken up the HTPC by pressing the power button, the WOL does work as before (for shorter-term sleeps.)

I was worried there may be inconsistencies in the sleep mode, hardware and general setup of PCs that might affect how they behave with the MCEC controller and WOL. Hopefully we will get a positive result when I test it again tomorrow morning and I’ll be able to avoid troubleshooting every power setting known to man. :crossed_fingers:

Hmmm…I don’t experience that. If my HTPC wakes up, it triggers pretty much instantly and I just have to wait a few seconds for the TV display to show the desktop. The reason I can say this with confidence is because whenever my HTPC starts ups or comes out of sleep, the CPU fan audibly whirs up - something that I never thought would come in handy but it helps determine when a WOL occurs in this instance.

Anyway - I’ll let you know what happens in the morning with the new WOL.

@hotelfoxtrotnovember Reporting in!
The WOL did not work again this morning - the activity button turns on the TV, etc but not the HTPC. With the HTPC still in sleep I then ran the wolcmd script on another network PC and it woke up the HTPC immediately.

So I realised (in a rare moment of clarity) that the issue occurs because the THR app is closed (or I turn off my tablet) and the app connection to the MCEC controller on the HTPC is severed. Upon re-opening the app to run the WOL cmd it obviously cannot reconnect to the HTPC because it is sleeping. I’m assuming that if the app is left idle for long enough the connection may also timeout.

To test this, I added single-command buttons to my setup (HTPC “PowerOff” & HTPC “PowerOn”). It took me 10 seconds to reproduce by simply sleeping the HTPC and then minimising the THR app on the tablet (the app was still running in the background, I just returned to the desktop.) That alone was enough to kill the connection - when I maximised the THR app, the WOL button did nothing. I’m sure you’ll be able to replicate this by doing the same thing on your ipad.

What I find strange here is that the HTPC does not wake up, but once manually powered on, the rest of the activity commands are executed (as previously discussed.)

Currently I have my HTPC sitting in the open to test, so it’s not a big deal to power on manually. But it will eventually be hidden away in a wall cabinet so it won’t be easy/practical to keep manually powering it on (especially for the rest of the family). Is there any way at all you can see this WOL working?

Thanks for your patience and support as always!

I think you are right about what is happening: when you put the HTPC to sleep and then close THR, THR drops/closes the connection (from its perspective) with the HTPC. Consequently, when you restart, the plugin’s onConnect() is called, it attempts to establish a connection the MCEC, and that hangs waiting for a timeout. I’m actually a little (but not a lot) surprised that pressing the button that sends the PowerOn doesn’t go through anyway, since I have observed that THR will interrupt onPoll() when a button push comes in. Apparently that isn’t happening so the button push is getting ignored at least until the connection timeout happens.

Regardless, I think it’s a simple fix. Go into onConnect() and just delete/comment out these last few lines:

    // connect to the MCEC server
    debugLog("  connecting...");
    mcecConnect();
    debugLog("  connected");

It shouldn’t break anything because mcecSend() checks that the connection is established before trying to send and the code now handles the WOL stuff before it even gets that far, so that should go just fine. Basically it just defers the connection to MCEC until the first command actually needs to be sent. That has the downside of introducing a slight delay for that first command, but I don’t think there’s another option since the timeouts can’t be controlled within THR.

Sorry for the somewhat rambling reply–I happened to check the forum for new messages shortly after you posted so I took a quick stab at what was wrong.

1 Like

Thanks for the quick response - especially trying to resolve it on the fly. At first attempt this fix didn’t work, but I’d only commented the code in my project plugin. So I removed the plugin completely from the project and re-added the new one with the code change. Works every time now, whether the app is minimised, closed or the tablet is turned off/on before WOL. The longest HTPC sleep I have tried so far is ~2 hours and it woke up immediately on the WOL button so it’s pretty much a certainty that it will work overnight (or indeed after days/weeks.)

Thanks so much for your efforts. This plugin and your fixes have made a huge difference to my setup. :+1:

I’m moving onto to fully testing my tweaked keyboard setup, browser buttons and shortcuts/scripts I’ve setup per activity so I’ll let you know if there are any issues with anything.

1 Like