It is currently March 28th, 2024, 1:37 pm

HotKey plugin 1.0

Plugins and Addons popular with the Community
Post Reply
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: HotKey plugin 1.0

Post by jsmorley »

Brian wrote:I have no plans to add this functionality to the plugin at this time. I am not really thrilled with addons/plugins that mimic user input, as I think they can easily be abused.

Having said that, there are some alternatives:
Nircmd: http://nircmd.nirsoft.net/sendkeypress.html
VB Script: https://social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx

-Brian
And:

https://autohotkey.com/
https://www.autoitscript.com/site/autoit/
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: HotKey plugin 1.0

Post by Virginityrocks »

Fair enough. I can respect that policy. Vbs scripts, .exe add-ons, and other programs I try to avoid as much as possible to avoid antivirus false positive hicups and just general simplicity of it all.
User avatar
killall-q
Posts: 305
Joined: August 14th, 2009, 8:04 am

Re: HotKey plugin 1.0

Post by killall-q »

You don't need a plugin or AutoIt to send keys, you can use Windows Scripting Host (WSH) built into Windows, basically a batch file.

Save the following to a .vbs file:

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Google Chrome"
WshShell.SendKeys "^n"
This will bring the application whose name contains "Google Chrome" to the front and send the keys Ctrl+N. You can run the VBS file from Rainmeter, it won't pop up a command window.

WSH SendKeys documentation

Thousands of people have downloaded one of my skins that uses a VBS file and I've had no complaints of anti-virus false positives.
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: HotKey plugin 1.0

Post by Virginityrocks »

Interesting! I'll check this out tomorrow! If this works out, the only missing piece may just be a way for Rainmeter to know the name of the focused window.
User avatar
killall-q
Posts: 305
Joined: August 14th, 2009, 8:04 am

Re: HotKey plugin 1.0

Post by killall-q »

You don't need the entire name, AppActivate will match the first (I don't know how the order is determined) open window whose name contains the string.
User avatar
Virginityrocks
Posts: 478
Joined: February 26th, 2011, 10:22 pm

Re: HotKey plugin 1.0

Post by Virginityrocks »

Oh I know. I just need a way for Rainmeter to know which program currently has focus, so that it can alternate commands based on that application name.

This script will change focus to that program (amazing!), and execute commands by sending keyboard shortcuts, but it still needs a way of determining which program the user wants to control.

The script works perfectly and I love you for it. I already know Jsmorley has made a plugin recently that will return the status of a window for any particular program, so that may fill in the missing gap so long as its simple enough to implement and doesn't take up hordes of resources checking the status on every single program window that I plan on creating individual commands for.
User avatar
killall-q
Posts: 305
Joined: August 14th, 2009, 8:04 am

Re: HotKey plugin 1.0

Post by killall-q »

You can skip AppActivate if you just want to send keys to whatever window is currently focused. SendKeys sends keys as if the user is pressing them, not to any particular application.

Oops I misunderstood what you meant.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: HotKey plugin 1.0

Post by kyriakos876 »

Hello, I noticed that HotKey Plugin doesn't work when I turn on my PC. I get it to work by, either restarting Rainmeter, or by closing a background program (Opens the moment the PC turns on, like Rainmeter.) that I use for my SmartTV. The program is "Smart Share" by LG. Is this Bug known? If yes, what should I do to resolve this?
User avatar
Brian
Developer
Posts: 2673
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: HotKey plugin 1.0

Post by Brian »

kyriakos876 wrote:Is this Bug known?
This hasn't came up before (as far as I know), but I am not it qualifies as a bug. Let me explain.

The plugin works by setting a 'global keyboard hook' on the Windows system. Since many programs (and the Windows system itself) need/can react to keystrokes regardless of which window has the keyboard focus, there is something called a hook chain that basically passes whatever key was pressed to each program one at a time. Of course the Windows system gets it first (for things like CTRL+ALT+DEL, and others). It then passes the keystroke to the next hook in the hook chain (usually its starts with the hook that is 'newest'). This happens before the window with keyboard focus actually gets the keystroke.

'Good' programs that use keyboard hooks are supposed to pass it along to the next hook. However, the hook chain can be broken easily by not calling the next hook.

Microsoft MSDN link (in the Remarks sections): https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx
Microsoft wrote:Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.
The plugin correctly calls the next hook here: https://github.com/brianferguson/HotKey.dll/blob/master/PluginHotKey/PluginHotKey.cpp#L413


So, I suspect that the LG software is installing a global hook to capture some keystroke (for whatever reason, probably navigation of folders, or maybe for some search function), however it is not correctly passing the key stroke to the next hook in the chain. This is my best guess.

kyriakos876 wrote:what should I do to resolve this?
To remedy this you could try delaying Rainmeter from starting before your LG Smart Share software. Or you could just manually start Rainmeter after you know the LG software has started. Or you could delay the loading of your specific skin by making another skin that will wait for specified amount of time before activating the skin that uses the HotKey plugin. Basically we want Rainmeter (or the skin that uses this plugin) to be the 'newest' in the hook chain to get first dibs on the keystroke.


I am curious to know if there was any error messages in the log when this happens? You may need to activate logging since the error might happen before the About dialog is initialized. https://docs.rainmeter.net/manual/user-interface/manage/#Logging

-Brian
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: HotKey plugin 1.0

Post by kyriakos876 »

Brian wrote:This hasn't came up before (as far as I know), but I am not it qualifies as a bug. Let me explain.

The plugin works by setting a 'global keyboard hook' on the Windows system. Since many programs (and the Windows system itself) need/can react to keystrokes regardless of which window has the keyboard focus, there is something called a hook chain that basically passes whatever key was pressed to each program one at a time. Of course the Windows system gets it first (for things like CTRL+ALT+DEL, and others). It then passes the keystroke to the next hook in the hook chain (usually its starts with the hook that is 'newest'). This happens before the window with keyboard focus actually gets the keystroke.

'Good' programs that use keyboard hooks are supposed to pass it along to the next hook. However, the hook chain can be broken easily by not calling the next hook.

Microsoft MSDN link (in the Remarks sections): https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx
The plugin correctly calls the next hook here: https://github.com/brianferguson/HotKey.dll/blob/master/PluginHotKey/PluginHotKey.cpp#L413


So, I suspect that the LG software is installing a global hook to capture some keystroke (for whatever reason, probably navigation of folders, or maybe for some search function), however it is not correctly passing the key stroke to the next hook in the chain. This is my best guess.


To remedy this you could try delaying Rainmeter from starting before your LG Smart Share software. Or you could just manually start Rainmeter after you know the LG software has started. Or you could delay the loading of your specific skin by making another skin that will wait for specified amount of time before activating the skin that uses the HotKey plugin. Basically we want Rainmeter (or the skin that uses this plugin) to be the 'newest' in the hook chain to get first dibs on the keystroke.


I am curious to know if there was any error messages in the log when this happens? You may need to activate logging since the error might happen before the About dialog is initialized. https://docs.rainmeter.net/manual/user-interface/manage/#Logging

-Brian
Oh I see... I guess you are correct. This doesn't seem to be the best written program in the world anyway :P I will ask about this to the LG's support page and see if that's the problem.


As for the error messages no, there were no error messages in the log. I'll come back if any update is available ^_^
Thanks Brian!
Post Reply