Decorum for the Forum:
  • Be nice. If you want to be mean, try Reddit.
  • No Piracy. If you want to be a thief, there are dark places on the internet dedicated to that.
  • No Cracking. Discussions on AnyDVD, DeUHD, DVDFab, UHDKeys and similar tools are not permitted here.
  • No Spamming. If you want to make a buck, work smarter... somewhere else.
  • No Adult Content. Half the internet is dedicated to adult content. This half isn't.

Privacy Policy: Click Here to Review (updated September 30, 2020)

Considering New App - Hotkey Monitor

General support forum for Chameleon MediaCenter (formerly MM Browser)
Teddyboy
Posts: 268
Joined: Wed Apr 25, 2018 10:30 pm
Location: San Diego, Ca

Re: Considering New App - Hotkey Monitor

Post by Teddyboy » Thu Feb 04, 2021 7:31 pm

Lol. I knew you’d start to tinker with it. ;) sounds like you’ve made some interesting progress. Not sure about blocking buttons. I think read somewhere on the eventghost forum that with a app specific plugin buttons where blocked when for specfic apps. When you switched focus to the app only those buttons were used. If you went back to the other app eventghost would switch back in a seamless manner. One of the demos I linked to showed that or something similar. I think Media Portal has complete control of the remote . I never had to do any registry tweaks during configuration.

If CMC has focus, then I don’t see how Jriver would get button presses. I recall in one of the videos that eventghost was sending commands to the app that had focus, and when you switched back then commands would be sent to it. He had a couple of plugins installed for the apps he used, and you could see eventghost switch focus.

Worse case you might have to tweak the registry to take control of the mce remote. Eventghost may have to do that because its the only way to get around a windows restriction or maybe you can write a handler for the remote. You’ve just started investigating, and barely scratched the surface of what event ghost can do. There will always be limitations. The question is can you work within those limits. Looking forward to see more of your tinkering.

EventGhost will also use other remotes not just the mce remote. It will also work with Logitech remotes. They have a list of remotes that work with it. You might want to join the forum and ask questions there. 😁
Mechanical Engineer, Solidworks junkie, Reef aquariums, sci-fi, weight training, orchids, Ferns, Kaiju, model kit building, balboa park, scripps aquarium

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Fri Feb 05, 2021 10:45 am

Teddyboy wrote: Thu Feb 04, 2021 7:31 pm If CMC has focus, then I don’t see how Jriver would get button presses.
JRiver would have focus if it was running.

Teddyboy wrote: Thu Feb 04, 2021 7:31 pm I recall in one of the videos that eventghost was sending commands to the app that had focus, and when you switched back then commands would be sent to it. He had a couple of plugins installed for the apps he used, and you could see eventghost switch focus.
I know how to do this, just not sure this is a level of functionality I want to tackle. Essentially, you disable HID input for the MCE IR receiver, so no app gets input from the remote. My MCE IR monitor app would still be able to see the button presses, because it taps in at a driver level. Then you have to monitor for which app has focus, apply an internal mapping specific to that app that converts button A to action B, and then send that action to the app that has focus. There a multiple ways to send actions: emulating keyboard strokes, sending Windows Messages via PostMessage or SendMessage to specific windows by their Handle ID, generating global HID output that looks like it originates from an MCE remote receiver, and for some apps I could even link directly to their API's. This kind of hand-tailored customization per app is a ton of work. And to do it right, you want to create a plug-in framework, so that other users can contribute new app definitions.

While I could create that, not sure why I would. GhostEvent and Girder already exist.

Teddyboy wrote: Thu Feb 04, 2021 7:31 pm Worse case you might have to tweak the registry to take control of the mce remote.
Doubtful I would do that, as that tweak disables the MCE Remote for all of Windows, then my app has to take over monitoring the buttons and mapping the output and sending it to the in-focus app as I described above. And then I get the joy of supporting that "solution".

After the testing I did yesterday, a plan has formed. I was able to map a button on the remote to launch CMC, even if my test app didn't have focus, and it did this quicker than the Windows Hotkey to launch a Shortcut method, so that's pretty much perfect with no registry tweaks. I also mapped another button to generate the ALT+F4 close hotkey, and that would close whatever program currently had focus, same as the CMC registry tweak today, but without the reg tweak. So all of that is pretty much perfect.

I will rebuild my test app into a Windows Service, and it will run with Admin privileges (required to see the MCE IR data stream). It will load it's configuration from the existing CMC.cfg file, so whatever buttons you configured in CMC will now be picked up by the new background service to get the same (but better) result.

Then in CMC I will revamp the MCE Remote Configuration page, and provide a toggle to either use the existing Windows Registry method, or the new Windows Background Service method. If you choose the background service, it will install the service for you, so it will always be running. That means that this solution will also be immune to the seasonal Windows updates that reset the registry, yay!!! I'll also have to provide an option to reset the registry to the Windows 10 default that disables actions for the MCE remote, otherwise these actions compete with each other.

Currently, CMC only configures up to 4 buttons: Launch CMC (default mode), Launch CMC (Movie mode), Launch CMC (Music mode), and Close (ALT+F4). I think this needs to be expanded to get the benefit of some of CMC's advanced functions. CMC has a lot of Hotkeys, for launching External Links, changing modes, clearing search filters, and even directly launching Steam and HDHomeRun. I could expand CMC to allow for some of these actions to be mapped to MCE remote buttons. The main problem is that there are only so many hotkeys available and so few MCE buttons to link them to, I have to limit how many can be assigned.

I also probably at least need to monitor for CMC being in focus, especially for these hotkeys, as otherwise this could cause unexpected results in other apps that make use of these buttons. DVDMenu is a good example of a button that does nothing in CMC, but is used in players, so I need to restrict any action to just CMC.

Teddyboy wrote: Thu Feb 04, 2021 7:31 pm EventGhost will also use other remotes not just the mce remote. It will also work with Logitech remotes.
Yes, I was looking at the list of plugins for input, and it is quite extensive. I'm thinking MCE remote support covers the vast majority of CMC users, as I've declared since the beginning that CMC requires a MCE remote. But I could potentially implement other plugins in my code to allow for other remotes in the future, should the demand arise.

One thing I'm unsure of is if I'm permitted to redistribute the MceIr.dll plugin with my code. I'm making some assumptions on it's origin, but I think it was developed as a plugin for GhostEvent - it's not Microsoft code. So I'm not sure if it's okay to re-bundle it. Worst case, I could force users to download GhostEvent just to get the DLL, but that's not exactly cool.

Also, one of my concerns was how this app would appear to virus scanners. So far, my own scanners haven't falsely flagged it, but I submitted it to VirusTotal.com, and it detected 3 engines. :cry: The SecureAge.APEX and Cynet false flags are pretty common, I get them a lot. But the VBA32 one is new, haven't seen that one before. Pretty amazing that 200 lines of code could be misconstrued so easily.

image.png
image.png (192.05 KiB) Viewed 3137 times
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Fri Feb 05, 2021 11:00 am

Pauven wrote: Fri Feb 05, 2021 10:45 am One thing I'm unsure of is if I'm permitted to redistribute the MceIr.dll plugin with my code.

I found the source code online: https://github.com/EventGhost/Extension ... /MceIr.dll

Seems like it's okay to distribute, the source is under GPL 2.0.
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Sat Feb 06, 2021 10:27 am

Argh, why does everything have to be so hard.

I had everything running perfectly as a desktop app. But the conversion to a Windows Service has been a nightmare. It's taken me over a day and a half just to get a Windows Service running. It's my first time creating one, so not too surprising.

Now that's it running, I'm recording button presses, but cannot issue commands. ALT+F4 and trying to open CMC.exe do nothing. Well, that's not exactly true. CMC launches, but it launches as a background process since it was launched by a Windows Service.

So now I have to learn how to have a background Windows Service interact with the current user's desktop... way too much fun.
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Sat Feb 06, 2021 11:42 am

Decision time. I would appreciate feedback.

Turns out that you cannot have a Windows Service interact with the current user's desktop (at least, not without cheating). This is a protection mechanism that Microsoft implemented beginning with Windows Vista.

So I either need to have a single "Desktop App" that runs when the user logs in, or a "Windows Service + Desktop App". There are pro's and con's to both approaches.


Single Desktop App
This app would run in the System Tray, monitoring for MCE button presses, and taking corresponding action.

Pro's:
  • Simpler single application
  • Consumes less memory (disk and RAM)*
  • Doesn't have to rely on communications between two apps
  • Single point of failure
  • Easier to support
  • Could still do Wake-on-LAN (WoL) on Login, almost as good as on System Boot
Con's:
  • Requires Administrative Rights to see MCE button presses, will probably nag user on every login!
  • Would NOT allow for Wake-on-LAN (WoL) on System Boot (this is a user request)

Windows Service + Desktop App
A Windows Service would start up when the system boots, always monitoring for MCE button presses. A second Desktop App running in the System Tray would communicate with the service, to receive button presses and take corresponding action.

Pro's:
  • Windows Service automatically runs with Admin rights - no annoying user nags on login
  • Would allow for Wake-on-LAN (WoL) on System Boot (this is a user request)
Con's:
  • Two programs = two points of failure
  • Requires settings up a communications channel between the service and desktop app.
  • Harder to troubleshoot and support
  • Might make upgrades more complicated (service has to be shutdown, probably requires admin rights to do that)
  • Consumes more memory (disk and RAM)*

*A note on memory consumption - this is probably irrelevant. Current the Windows Service I have programmed is about 2 MB in size, and consumes about 1.5 MB while running, so it's very tiny. Splitting the functionality into two programs, and adding a communications link, will presumably more than double those sizes. I would estimate 5 MB in disk storage, and 4 MB in RAM. On hardware sufficient to run Win7+, these numbers are likely small enough to not be a consideration.


My Thoughts
Of the two options, I'm currently leaning towards the Windows Service + Desktop App approach, primarily due to the the requirement for Admin Rights. I fear that the "Run as Administrator" prompt every time the alternative single Desktop App is started is going to be a real issue.

The ability to do WoL on Boot is a nice bonus, but there are other 3rd party tools available that can accomplish this so that's no strong driver of this decision.

Though if there was a way to configure a desktop app to auto-start at login "as Administrator" without a nag screen, I'd probably choose the single Desktop app approach.
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Sat Feb 06, 2021 1:12 pm

Quick Update:

I just played around with "mailslots" for Interprocess Communications (IPC), and I like it. I'm able to send small messages from Client to Server very reliably and with instantaneous response.

I was also able to send messages from a Client running As Admin to a Server running without Admin, and this worked perfectly too.

The Client is also able to quickly detect when the Server is down and get back confirmation that the Server has handled the message, making the communication channel pretty robust.

For this to work with my app, I would have the "CMC MCE IR Monitor" Windows Service running as the IPC Client with Admin rights, and the System Tray Desktop App "CMC Button Handler" running as the IPC server. You press a button on the MCE remote, the "CMC MCE IR Monitor" immediately sees the button press and sends it to the CMC Button Handler.

Because of how mailslots work, I could have multiple Clients all sending messages to the single Server. In this case, each client could be a different Windows Service monitoring different kinds of input devices. I could have one for MCE IR, and another for Logitech, for example, and they could be running at the same time, and sending signals to the single SysTray app.

Based upon these results, I'm going to try implementing the "Windows Service + Desktop App" approach I outlined above.
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Sun Feb 07, 2021 11:09 am

Another progress update - things are coming along swimmingly!

I now have a Windows Service communicating with a Desktop App. So far it's been perfectly stable and I haven't seen any button misses. Performance is still pretty much instantaneous - I can't discern any processing lag at all, and in general the remote feels much more responsive to launching CMC than the Registry method.

Here's a preview of the Desktop App (which will be turned into a System Tray icon), which allows you to monitor the button presses:

image.png
image.png (220.18 KiB) Viewed 3122 times

Notice that the configured button actions are executed, and the app can even determine when CMC gains or loses focus. This will be critical for the proper handling of CMC Hotkeys, which should only be issued if CMC has focus, not to other apps.

This is all with the HID option still enabled, so MCE Remote buttons configured in the Registry still obey their configuration, so essentially this app is letting you add actions to otherwise unconfigured buttons.

Reading between the lines, you might surmise that these capabilities hint at this app being able to have individually configured actions for different apps - and I agree! While I was very hesitant before, I'm now more open to the idea of having buttons custom configured for other apps. I'm still not sure I want to go down the path of disabling HID input for the remote and forcing my app to send all commands, but I see little harm in allowing my app send commands for otherwise unconfigured buttons. Baby steps...
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Sun Feb 07, 2021 11:46 am

This is working better than I hoped!

The ability to determine when CMC has focus has allowed me to program different actions. In the screenshot below, when CMC is not running then TV launches CMC in Movie mode, and Music launches CMC in Music mode. Once CMC is running and has focus, those exact same buttons instead issue the built-in CMC Hotkey to switch between the Movie and Music libraries.

image.png
image.png (244.69 KiB) Viewed 3121 times

I should have done this years ago.... sorry guys.
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

Teddyboy
Posts: 268
Joined: Wed Apr 25, 2018 10:30 pm
Location: San Diego, Ca

Re: Considering New App - Hotkey Monitor

Post by Teddyboy » Mon Feb 08, 2021 5:01 pm

Looks really good Paul. I know your just taking small steps, but I like what I see so far. Have your tried this with other apps that interact with CMC such as any of the players you support? Would you just allow the default buttons that the players already have or allow for button customization. Sometimes I will press the wrong button and jriver will pop out of display view. Would you consider having profiles for the supported player. I know! I know! Baby steps, but it was interesting to see inside the desktop/tray app when CMC would no longer have focus.

You mentioned that the registry still having buttons configured for the remote. Is there any fighting between your solution and the registry? You did mention that you probably would offer a option for either using registry configuration or do it through the service. Personally I would opt for the service for my install, as it appears to be much more responsive and configurable. If you don’t really need to disable HID then don’t do that, but I think it should be one or the other. You could offer basic button configuration through the registry like you do now, or this new solution which can lead to better response and more configuration option for CMC and possible other app using preconfigured profiles. Really intrigued with what you’re doing.
Mechanical Engineer, Solidworks junkie, Reef aquariums, sci-fi, weight training, orchids, Ferns, Kaiju, model kit building, balboa park, scripps aquarium

User avatar
Pauven
Posts: 2777
Joined: Tue Dec 26, 2017 10:28 pm
Location: Atlanta, GA, USA
Contact:

Re: Considering New App - Hotkey Monitor

Post by Pauven » Mon Feb 08, 2021 6:12 pm

Teddyboy wrote: Mon Feb 08, 2021 5:01 pm You mentioned that the registry still having buttons configured for the remote. Is there any fighting between your solution and the registry?
Yes, currently they fight. It only works correctly if you configure a button that otherwise does nothing. Which could actually have some interesting applications - imagine having a button "A" configured to do "X" in the registry, but configured to do "Y" in my app. Press A and get both X and Y. Is there a valid use case for that? Probably not.

So for right now, I'm only testing buttons that otherwise don't do anything. It's also possible to successfully configure buttons to do things in CMC, that otherwise do stuff in other apps but not in CMC. For example, "Record" does nothing in CMC, but activates the Record function in HDHomeRun. I can configure it to do something only for CMC, and the existing behavior in HDHomeRun is unaffected.

To be able to configure and control all buttons, you have to disable the HID input for all of Windows, which then makes my app 100% responsible for monitoring keypresses and issuing commands. Yikes. But I think that this is ultimately what some users will demand.

Teddyboy wrote: Mon Feb 08, 2021 5:01 pm Have your tried this with other apps that interact with CMC such as any of the players you support?
Yes, a little bit. It seems to work similarly in other apps - as long as the button doesn't already have an action, you can configure an action for it. But if it already has an action, configuring a second action would produce competing actions as you suggested.

I haven't tested PowerDVD yet - that app is notoriously bad about stealing button presses and hiding them away from the rest of the system. I'm thinking my new app, since it ties directly into the MCE IR6 driver, will overcome this issue.

Teddyboy wrote: Mon Feb 08, 2021 5:01 pm Sometimes I will press the wrong button and jriver will pop out of display view.
The only solutions are to either A) disable MCE remote HID input via the Registry for all of Windows (making my app or something like EG/Girder 100% responsible for monitoring buttons and issuing actions), or B) modifying the Registry to disable just those buttons so they have no action, then you could remap them using my app and make them do what you want.

*NOTE: method A is what EG recommends, but my app isn't to the point it could take over 100% of all actions.

Without registry tweaks, then the only thing my app could do is allow you to assign a secondary competing action for the same button, making the problem twice as bad. You know, for masochists...

Teddyboy wrote: Mon Feb 08, 2021 5:01 pm You did mention that you probably would offer a option for either using registry configuration or do it through the service. Personally I would opt for the service for my install, as it appears to be much more responsive and configurable.
The more I develop it, the more I really like the new service. I will definitely be abandoning the Registry approach for my own personal use. And I'm already expanding the functionality much more than I originally planned because it has so much potential.

That said, I'm not ready to pull the plug on the Registry based solution for existing users, since the new solution hasn't proven itself yet. Typically I prefer to leave working tools in place for users who prefer them. Similar to what I did for CCC vs. CME.

Teddyboy wrote: Mon Feb 08, 2021 5:01 pm Would you consider having profiles for the supported player.
Yes. In fact, I'm already coding this. I spent a few hours doing data design just trying to figure out how I want to store all this configuration data. And I have a pretty strong concept drawn up, but there is one aspect I haven't quite figured out. Let me try to describe it so you (and others) can comment on how you think it should work.

The Concept
Button configuration will be organized as Modes as the parent, and Buttons with Actions as the children. Modes are mostly apps, i.e. CMC, PowerDVD, JRiver, MPC, HDHomeRun, but I also have a special Mode called Global. Each Mode will have it's own configuration page, so you can configure the buttons you want for CMC, then switch over to JRiver and configure the buttons you want there. Ditto for Global.

Global buttons currently take precedence - if you configure a button in Global, it would not be available to configure in any other app Mode. A good example of this is the "Start" button (aka The Big Green Button). If I assign it to launch CMC, then no matter where I am or what app I'm using, pressing Start will launch CMC. Another good example of a Global button is the Close action - perhaps you assign the "Red" button to be Close, and no matter where you are, pressing "Red" issues the ALT+F4 close action.

Then for buttons that you didn't assign on Global, you can assign to each app Mode to do different actions as desired. For example, you might configure "Live TV" to switch to the "Show Media Type TV" filter in CMC, but switch to Live TV in HDHomeRun. Since the app will know which program you're currently using, it can apply the correct action for that Mode.

The Gap
As fairly complete as the above concept is, I feel there is one scenario that isn't handled. I'm not sure what to call it, but the best way to describe it is a Global button that get's overridden by a Mode's configuration, so kind of the opposite of a Global.

For example, let's say you want to make the "My TV" button always launch HDHomeRun, unless you are in CMC where you want it to switch to the "Show Media Type TV" filter. So the Global action is to launch HDHomeRun, but it get's overridden by CMC's configuration for that same button.

Essentially, what I'm describing is two types of Global buttons, Global Static, and Global Overridable. (Yeah, I hate my terminology too. Please feel free to help me with the lingo). The question is, how do I design my app to let users define this configuration?

One idea is to have two global tabs: Global Static and Global Overridable, but I think this might be confusing. This config page will be set up with tabs across the top, so it would look something like this:

Code: Select all

Global Static  |  Global Overridable  |  CMC  |  DVDFab  |  JRiver  |  HDHomeRun  |  MPC  | PowerDVD  | VLC  | etc...
-------------------------------------------------------------------------------------------------------------------------
The other way would be to add a toggle to each Global assignment to either make it overridable or static, more like this:

Code: Select all

[GLOBAL] |  CMC  |  DVDFab  |  JRiver  |  HDHomeRun  |  MPC  | PowerDVD  | VLC  | etc...
------------------------------------------------------------------------------------------
GLOBAL BUTTON CONFIGURATION - APPLIES TO ALL APPS SYSTEM WIDE:

Button "Red"    -  Action "ALT+F4"     - Overridable: No
Button "Start"  -  Action "Launch CMC" - Overridable: No
Button "Guide"  -  Action "ALT+G"      - Overridable: Yes
That's a high-level of where I am, and the last real design challenge I'm working through. Though the act of writing all this out has helped me think through it again, and I'm leaning towards the second method, having an overridable toggle on each Global button assignment.
President, Chameleon Consulting LLC
Author, Chameleon MediaCenter

Post Reply