Overwrite global Windows hotkeys to hotkey of application

Get help with using AutoHotkey and its commands and hotkeys
SashaChernykh
Posts: 26
Joined: 01 Sep 2016, 04:04
GitHub: Kristinita
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] [Download] GeSHi © Codebox Plus

{
"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:



But if I press LWin+2, my shortcut also not worked for me.

Do not offer



It's worked for me, but copy command only for example. In real I need shortcuts without redirects to other shortcuts.


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

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 06:38

Try

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

; replace "Notepad" with the ahk_class of Sublime 

#2::
IfWinNotActive ahk_class Notepad
Send, #2
; else
; Send, ^c
return
SashaChernykh
Posts: 26
Joined: 01 Sep 2016, 04:04
GitHub: Kristinita
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] [Download] GeSHi © Codebox Plus

#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: 1957
Joined: 17 Oct 2015, 20:28

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 07:57

Code: [Select all] [Download] GeSHi © Codebox Plus

#IfWinActive ahk_class PX_WINDOW_CLASS
#2::Send ^c

#If ; reset context-sensitivity


Does that work any better?
qwerty12
Posts: 354
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 08:05

Code: [Select all] [Download] GeSHi © Codebox Plus

#IfWinActive ahk_class PX_WINDOW_CLASS
$#2::ControlSend, ahk_parent, % SubStr(A_ThisHotkey, 2)
#IfWinActive


EDIT: #IfWinActive sets the last found window
guest3456
Posts: 1974
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: 26
Joined: 01 Sep 2016, 04:04
GitHub: Kristinita
Contact:

Re: Overwrite global Windows hotkeys to hotkey of application

16 Nov 2016, 08:34

qwerty12 wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

#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: 354
Joined: 04 Mar 2016, 04:33
GitHub: qwerty12

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] [Expand] [Download] GeSHi © Codebox Plus



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: 26
Joined: 01 Sep 2016, 04:04
GitHub: Kristinita
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.
gongnl
Posts: 69
Joined: 05 Jan 2015, 03:57
Location: /gongnltmp/

Re: Overwrite global Windows hotkeys to hotkey of application

20 Mar 2017, 17:21

thanks

Return to “Ask For Help”

Who is online

Users browsing this forum: Didier3L, Jack and 21 guests