Overwrite global Windows hotkeys to hotkey of application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SashaChernykh
Posts: 32
Joined: 01 Sep 2016, 04:04
Contact:

Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 06:16

Briefly

How I can disable global Windows hotkey in application and instead it hotkey for command of these application?

Detail

I work in Windows 10 in Sublime Text, path to Sublime Text exe file is E:\Sublime Text 3. For example, I want to set shortcut LWin+2 for copy command. I make a shortcut in Sublime Text settings:

Code: Select all

{
"keys": ["super+2"],
"command": "copy"
},
But my shortcut not work, because LWin+2 is Global Windows shortcut.

Did not help

I read page Overriding or disabling hotkeys.
  1. #2::return disable LWin+2, but I can not enable these shortcut for Sublime Text commands.
  2. I try code:

Code: Select all

$#2::
IfWinActive ahk_class Notepad
	return
Send #2
return
But if I press LWin+2, my shortcut also not worked for me.

Do not offer

Code: Select all

$#2::
IfWinActive ahk_class Notepad
	return
Send ^c
return
It's worked for me, but copy command only for example. In real I need shortcuts without redirects to other shortcuts.


Thanks.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 06:38

Try

Code: Select all

; replace "Notepad" with the ahk_class of Sublime 

#2::
IfWinNotActive ahk_class Notepad
	Send, #2
; else
	; Send, ^c
return
SashaChernykh
Posts: 32
Joined: 01 Sep 2016, 04:04
Contact:

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 07:25

@GEV, instead of Notepad I get in Window Spy and insert class for Sublime Text — PX_WINDOW_CLASS.

Image

My code:

Code: Select all

#2::
IfWinNotActive ahk_class PX_WINDOW_CLASS
    Send, #2
; else;
   ; Send, ^c
return
But this code not working for me. Nothing occurs if I press LWin+F2 like #2::return.

Thanks.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 07:57

Code: Select all

#IfWinActive ahk_class PX_WINDOW_CLASS
#2::Send ^c

#If ; reset context-sensitivity
Does that work any better?
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 08:05

Code: Select all

#IfWinActive ahk_class PX_WINDOW_CLASS
$#2::ControlSend, ahk_parent, % SubStr(A_ThisHotkey, 2)
#IfWinActive
EDIT: #IfWinActive sets the last found window
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 08:22

There have many topics started about people having trouble with Win10 where these WinKey hotkeys cannot be overridden. If nothing ends up working, it may just be a Win10 thing that you have to live with

SashaChernykh
Posts: 32
Joined: 01 Sep 2016, 04:04
Contact:

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 08:34

qwerty12 wrote:

Code: Select all

#IfWinActive ahk_class PX_WINDOW_CLASS
$#2::ControlSend, ahk_parent, % SubStr(A_ThisHotkey, 2)
#IfWinActive
EDIT: #IfWinActive sets the last found window
@qwerty12, thank you, it's worked! But I have problem: if I press LWin+2 second time, Windows start menu are shown for me.

Image

I tried add in my code ~LWin Up:: return, but problem remained for me.
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 08:54

SashaChernykh wrote:@qwerty12, thank you, it's worked! But I have problem: if I press LWin+2 second time, Windows start menu are shown for me.
Eurgh, sorry. I thought the similar problem I had on my system was StartIsBack's fault (its keyboard hook is insanely annoying when it comes to the Windows key). With it turned off, I get the same after about five presses. Hopefully I'm just missing something and someone can correct me.

Meanwhile, I have another way for these specific keys (Win+{1-9}), but I don't know if you're going to like it...

Code: Select all

DetectHiddenWindows On
IsWindow := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "user32", "Ptr"), "AStr", "IsWindow", "Ptr")

#IfWinActive ahk_class PX_WINDOW_CLASS
#2::
{
	if (!DllCall(IsWindow, "Ptr", taskbarIcons))
		ControlGet, taskbarIcons, Hwnd,, MSTaskSwWClass1, ahk_class Shell_TrayWnd
	Control, Hide,,, ahk_id %taskbarIcons%
	ControlSend, ahk_parent, % SubStr(A_ThisHotkey, 2)
	Control, Show,,, ahk_id %taskbarIcons%
}
#IfWinActive
EDIT: The start menu actually isn't shown with the above, but that's only because this code is slower to work (which brings in its own problems like the key not getting properly sent to Sublime sometimes). You may be able to sort the original code out by introducing your own artificial delay after the key is sent to Sublime, like with Sleep or SetControlDelay, but that's probably not entirely reliable, either. I see what guest3456 means...

Some links that may help:

https://autohotkey.com/docs/misc/Override.htm
http://winaero.com/blog/disable-certain ... indows-10/ - namely, see if the DisabledHotkeys registry value helps any
SashaChernykh
Posts: 32
Joined: 01 Sep 2016, 04:04
Contact:

Re: Overwrite global Windows hotkeys to hotkey of application

19 Nov 2016, 06:22

Unfortunately, I can not find good solution use other programs, not only AutoHotkey :( . See my question in Super User.

Thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee and 156 guests