Is it possible to re-assign the Win+L hotkey to another executable/shortcut?
Use-case - I would like to switch off the monitor of my laptop as soon as it is locked. I know of a executable which can lock and turn off the monitor but I do not want to change the way the system is locked (by running the program explicitly or by some other shortcut). It would be best if Win+L can be assigned to this executable.
You need to set the following registry key to completely disable the Windows locking feature:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableLockWorkstation"=dword:00000001
And restart the computer.
This works on Win7, Win8 and Win10
The Win+L is a system assigned hotkey and there's no option to disable it. This means there's no way for an application to detect it, unless you use a low-level global keyboard hook (WH_KEYBOARD_LL). This works in XP SP3; haven't tested it in Vista though:
LRESULT CALLBACK LowLevelKeyboardProc(int code, WPARAM wparam, LPARAM lparam) {
KBDLLHOOKSTRUCT& kllhs = *(KBDLLHOOKSTRUCT*)lparam;
if (code == HC_ACTION) {
// Test for an 'L' keypress with either Win key down.
if (wparam == WM_KEYDOWN && kllhs.vkCode == 'L' &&
(GetAsyncKeyState(VK_LWIN) < 0 || GetAsyncKeyState(VK_RWIN) < 0))
{
// Place some code here to do whatever you want.
// ...
// Return non-zero to halt message propagation
// and prevent the Win+L hotkey from getting activated.
return 1;
}
}
return CallNextHookEx(0, code, wparam, lparam);
}
Note that you need a low-level keyboard hook. A normal keyboard hook (WH_KEYBOARD) won't catch hotkey events.
The registry-based solution on its own completely disables locking the system (even via the Start menu).
Here is a method that actually provides a way to lock the computer without the Win-L chord. Locking can either be done via a shortcut on the taskbar or by pressing them in sequence followed by Enter.
First, create a batch file that can toggle system locking and trigger the lock itself; instructions for doing this are taken from a forum post:
Create reg-edit files for turning system locking on or off. This is the same as in Brent Foust's answer.
In DisableLockWorkstation.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableLockWorkstation"=dword:00000001
In EnableLockWorkstation.reg:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableLockWorkstation"=-
Run the reg-edit script for disabling the system lock.
Create a batch file to toggle the feature using the .reg files:
regedit /S EnableLockWorkstation.reg
rundll32.exe user32.dll,LockWorkStation
regedit /S DisableLockWorkstation.reg
Now, you can create a shortcut and pin it to the taskbar:
Right-click on the batch file and create a shortcut.
Right-click on the new shortcut, edit the shortcut properties, and change target to cmd.exe /C "<path>\lock.bat", where <path> is the full path to the lock.bat file.
The shortcut should now be pinnable to the taskbar (this is not true prior to manually changing the target); it can be dragged there as normal.
(Note that you may also want to change the icon to something like a padlock before pinning the shortcut to the taskbar.)
As mentioned above, once you've completed the above procedure, you should be able to lock the computer using Win, L, Enter in sequence (not as a chord--though see below for a solution using Ctrl-Alt-L as a chord). This is because that sequence is interpreted as follows:
Win -- brings up the Start menu, although you don't actually need to wait for it to load
L -- searches for the custom lock-script; on my machine, the lock.bat shortcut was always the first L result if it was the only shortcut on my taskbar starting with L. (Verify this before attempting to lock your computer this way!)
Enter -- once the search finds an item, it will be launched--i.e. the shortcut will be called, and your computer will lock. You do not need to wait for the search to load; you can quickly press Win, L, Enter in sequence and walk away. The screen will not lock immediately, but it should lock within a few seconds.
Below is a picture of the taskbar shortcut I made (using this icon):
EDIT: Using a chord, such as Ctrl-Alt-L
In the comments below, user lub094 suggests a way to assign the shortcut to the chord Ctrl-Alt-L (or whatever shortcut you'd like). I have not taken the time to test this because I've re-enabled the system shortcut, but I assume that it works.
Use the built-in shortcut-creation feature to assign the chord:
Place the shortcut itself in the Start Menu folder:
"C:\Users\ [user_name]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\ [custom_folder]\"
Looks like you can't.
You can disable all built-in Windows
hotkeys except Win+L and Win+U by
making the following change to the
registry (this should work on all OSes
but a reboot is probably required):
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
NoWinKeys REG_DWORD 0x00000001 (1)
(http://www.autohotkey.com/docs/misc/Override.htm)
But you could try using Tweak UI. Under the Explorer tree view item, uncheck "Enabled Windows+X" hotkeys. Hoekey also might work, haven't tried it. Source.
The #FrancoisB method works for Win8 and Win7. To automate the solution:
Create a text file with the .reg suffix (DisableWinL.reg, for example)
Paste the following content and save the file:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableLockWorkstation"=dword:00000001
Open that file with RegEdit (double-click should work) to execute the change.
This file can be copied to a new machine to repeat the process. And another one named something like "EnableWinL.reg" could be created that re-enables the Win+L key:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]
"DisableLockWorkstation"=dword:00000000
Use power toys for windows 10.
There you have options to remap shortcuts..
download power toys
Related
I have to use USB barcode scanner in application running on remote desktop. This scanner is being recognised by Windows as keyboard. When I try to scan barcode however, every 3th or 4th character is being changed to another one. When I type numbers by hand, they are being correctly written. The question is: is there any way to programmatically produce "lag" on keyboard globally? I would like to create for example a half second gap between keyboard input events and a result on the screen. Some time ago I worked with Windows hooks, and I was able to change keyboard input globally, but I remember I had problems with delaying it. Is there any other way?
you can make an autohotkey script to listen to a keyboard input, wait and then press the same keyboard button.
once you have intalled AHK(autohotkey) , you can do a AHK script whit the intructions that are in the ahk documentation.
Right-Click on your desktop.
Find "New" in the menu.
Click "AutoHotkey Script" inside the "New" menu.
Give the script a new name. Note: It must end with a .ahk extension. Ex. MyScript.ahk
Find the newly created file on your desktop and Right-Click it.
Click "Edit Script".
A window should have popped up, probably Notepad. If so, SUCCESS!
i::
sleep, 500 ;
Send, i
Return
(you can change the "i" for other keyboard keys).
a function would reduce the amount of code that you use, but i don't know how to do it in a AHK script
I need to create a GUI working on windows that can be activated by pressing short cuts.
1. is it possible without setup class?
2. if not possible, just achieve pressing hotkeys and activate my program--how should i code it out--would be enough
thanks (I am using Qt for vs2012 add in to do the GUI)
I put some code up that starts a thread that does this. It is windows specific, but it does the job.
Clipboard Shortcut/Hotkey binding with Qt outside of application
One alternative to all of this, is to go to a shortcut to your program, go to its Properties, and then click on the shortcut area and type your desired shortcut. As long as it doesn't overlap with existing hotkeys that are registered in windows, it should work, without a hidden presence of your app in the system tray or some other background thread.
Hope that helps.
libqxt offers a QxtGlobalShortcut class that does what you want.
I've got two keyboards attached to my computer. A normal full-size keyboard and a numeric keypad. I want to "remap" the keys on the numeric keypad, but leave the full keyboard alone. So, when the user presses "5" on the keypad it would get remapped to the "Media Play" key, but if the same "5" was pressed on the keypad of the full keyboard, I'd get a "5". In essence, I want to turn that seperate numeric keypad into a media control device.
Unfortunately I'm not sure how to make this work. There is a "Raw Input" feature of Windows which allows to distinguish between keyboards, but that only allows to read the keys - not remap them. There are keyboard hooks (low level and high level) which can remap the keystrokes, but they don't distinguish between keyboards.
Can I make a combination of the two methods work? For that I'd have to be sure that the raw input message is processed before the keyboard hook kicks in. Is that so?
Also, I've read that Windows for some reason does not allow to use Raw Input and Keyboard Hooks in the same process. I could work around that by making 2 different processes, but that becomes more fragile because of communication latency (keyboard hooks have very limited time in which they must complete their work).
Is this doable at all?
In the end it turned out I needed a custom keyboard driver to accomplish this. Fortunately I found one ready for taking - Interception. The app is ready and works perfectly. :)
I wanted to expand on the answer by Vilx as I've revisited this post several times, and I've only just managed to remap my second keyboard so the keys act uniquely. This is done using Interception and Intercept together, and it's the only working solution that I've managed to get working so far.
I'm also looking into using a raspberry pi to remap a second keyboard. Although early days, I think it it's achievable: Plug keyboard into Pi, plug Pi into PC and write script to turn input keycodes into customized output commands / keycodes. Will update when I have tested.
My working Intercept solution is completely based on a Github tutorial by TaranVH which details the process the best so far. I've copied his solution below with some amends of my own.
DOWNLOADING INTERCEPTION:
Navigate to this page: https://github.com/oblitum/Interception
Click on "download the latest release."
Click on Interception.zip to download it.
Unzip the file to a folder on your computer - I recommend using a folder location that won't ever move. I put my Interception folder into C:\Program Files\ and I'll be using this location in my examples.
INSTALLING INTERCEPTION:
Open a terminal as administrator and type cd "C:\Program Files\Interception\command line installer"
Hit Enter
Now, type in the following line of text exactly as shown:
install-interception.exe /install
Hit Enter
Once the program installs sucessfully, you still must restart your computer in order to complete the installation.
(If you ever want to UNinstall interception, watch this): https://www.youtube.com/watch?v=Hn18vv--sFY
INSTALLING INTERCEPT - (This is different from intercepTION!)
Download Kamaz's intercept.exe zip from one of these locations:
http://octopup.org/img/code/interception/intercept.zip
https://github.com/TaranVH/2nd-keyboard/blob/master/Intercept/intercept.exe
Unzip it if it's a .zip file and locate intercept.exe
To keep these files all in one place, I moved intercept.exe into C:\Program Files\Interception\
Reboot your system.
SETTING UP INTERCEPT
Plug in your second keyboard and ensure that it is working normally.
Go to where you saved intercept.exe and double click to open.
Intercept will open as a terminal, and from there you should have basic instructions to start remapping your keyboard.
Type a to add a key.
On the SECONDARY keyboard, press the Q key once. (this is the key that you are remapping)
You will be prompted with Enter combo for this trigger, end with ESC.
Carefully execute the following keystrokes (it doesn't matter which keyboard): Win + E (That is: hold down the windows key while pressing the letter E. I've found you need to do this quickly and accurately, if you hold down too long, extra keypresses are added)
When I did it, this was shown in the terminal: [Left Windows]↓ [E]↓ [E]↑ [Left Windows]↑
Press Esc and you will be prompted to label the script
I labelled mine Q->WinE so I knew what it was doing.
Press Enter to accept the label
Press S to save the filter, or C to cancel if you made a mistake.
Add more filters or close the terminal.
USING INTERCEPT
Now you've set up a custom key command, you need to apply the filter to use it.
Open up intercept.exe
Press Y to apply the filters, you will get confirmation that the filters have been activated.
Now, when you press Q on your second keyboard, Intercept will change the command to Win+E which will open File Explorer.
Caveat:
Please read TaranVH githubs page on this https://github.com/TaranVH/2nd-keyboard/tree/master/Intercept as it provides some further details and troubleshooting.
Please take care to follow the instructions very exactly as there's very little error handling in this process
In this article http://vlaurie.com/computers2/Articles/remap-keyboard.htm is explained how to remap keys of a keyboard. Hope that helps.
Microsoft's powertoy is relatively well known. But it requires you to open a cmd one level above, from where you'd usually like. So I found this nice app, CmdOpenInstall (let's make the man some traffic :-) - it enables you to open cmd in the current directory.
Is there a way to assign a keyboard shortcut to the command (which appears on right click menu) ? How ?
p.s. I know this is maybe not a strict programing subject, but I still think it has more chances of being answered here then on SF.
If you find the context menu entry in the registry (I think it would be in HKEY_CLASSES_ROOT\Folder\shell somewhere), you can prefix the character you want as hotkey in that menu with a & to force it as keyboard accelerator.
But apart from that you can't (at least not without addditional tools I don't know any of) make direct keyboard shortcuts to functions in a context menu. But I think something like Menu key and another letter comes close enough in everyday use.
Here are the registry keys I use to easily open command windows. Here 'C' is the shortcut key.
To use, save to a .reg file and merge into your registry.
Windows Registry Editor Version 5.00
;Right click on folder and open up command window
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmd1]
#="Open &Command Prompt Here"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\cmd1\command]
#="cmd.exe /k pushd \"%L\""
;Right click on any file and open up command window
[HKEY_CLASSES_ROOT\*\shell\cmd1]
#="Open &Command Prompt Here"
[HKEY_CLASSES_ROOT\*\shell\cmd1\command]
#="cmd.exe %1"
I am currently working on a program to immediately clear the list of previously-run-commands which appears in the Windows Start -> Run dialog. The procedure for clearing this list by removing the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU key is well documented; however, before these changes take effect, it seems to be necessary to do one of the following:
Restart the computer
Select Start -> Shut down, and then select Cancel.
Neither of these is ideal for the task I am trying to accomplish: #1 is extremely disruptive to the user, and #2 appears to require additional user interaction.
Does anyone know how to immediately (and programmatically) force a reload of this information without requiring any user interaction, while also minimizing disruption of the user's other activities? I would like for the user's Run history to be cleared out immediately after executing my program, without requiring any further action on their part (such as using the "Shut Down" -> "Cancel" trick in #2 above) or forcing a reboot.
Or, to approach the problem from a different angle: When clicking Start -> Shut Down -> Cancel, Windows Explorer reloads the RunMUI key. Is there a way to force a similar reload without having the user select Shut Down and then Cancel?
Things I have already tried:
Monitoring the explorer.exe status using procmon while selecting Shutdown and then Cancel. I see Explorer writing to the RunMRU key, but have not been able to determine what triggers this.
Numerous Google searches along the lines of "reload runmru without reboot". Most results still recommend method #1 above, although a few suggest #2.
Limited MSDN API examination. The RegFlushKey call appears promising, but I haven't ever used it before, so I don't know if it will apply to registry information cached by different processes.
Any suggestions or other information would be greatly appreciated.
Have you tried ccleaner?
http://www.ccleaner.com/
Not a full answer to your question, but I did find a third way to trigger the clearing of the run command from this article in PC Mag.
Killing explorer.exe and then restarting it will also clear the run list after the registry modification.
I have a nasty hack for you. Show the window programatically, hide it immediately (programatically) and click cancel on it (well, you guessed, programmatically).
You might try looking for the icon cache flush API, or other ones, I wouldn't be too suprised if they had side effects like the one you are looking for.
I've seen instances where it actually works, even the F5 key doesn't work? Try this, ctrl>alt>delete then go to task manager, processes tab...end explorer.exe. Then click on file new task and type explorer.exe, then check...does that work?
Windows XP
Right click on the taskbar
Properties menu option
Start Menu tab
Customize button
Programs pane
Clear List
Click on OK
This calls a Windows API function that refreshes the explorere.exe taskbar process and also clears the list (no need for registry edits).
As far as I know, it relies on the explorer.exe process that hosts the start menu/taskbar/desktop being closed and reopened. There is no "clean" way to do this that I am aware of.
If you really need to do this without user interaction, you need to close all explorer.exe processes and relaunch one.
Here's a rudimentary C# program to do that;
using System.Diagnostics;
Process[] procs = Process.GetProcessesByName("explorer");
foreach (Process proc in procs)
{
proc.Kill();
}
Process.Start("explorer.exe");
Note that this will close all "Windows Explorer" windows open, and may or may not open an additional "Windows Explorer" afterwards.
I just tested that on Windows XP 32bit, and it did indeed clear the Run command cache.
HKEY_CURRENT_USER\ Software\ Microsoft\ Windows\ CurrentVersion\ Explorer\ RunMRU\