How to stop Notepad++ intercepting back/forward keypresses?
-
I have just updated to Notepad++ 7.2.2, and I’m running on Windows 10.
I have a Microsoft keyboard with specific “Back” and “Forward” keys, which are usually mapped to Back/Forward in web browsers, etc. I have remapped them to change virtual desktops in Windows 10, and I use them a lot.
Notepad++ seems to be intercepting these key presses, and uses them to change to previous/next tab. So, if Notepad++ has focus, I cannot change virtual desktop with those keys.
How can I stop Notepad++ intercepting the key presses? I have tried clearing the keyboard shortcuts for next/previous tab, but that had no effect. I guess the back/forward button thing is more of a mouse shortcut than a keyboard shortcut, but I can’t find any option to disable the mouse shortcut either.
-
Are you sure it is next/previous tab and not something similar?
You need to figure out exactly what is the key sequence that is being sent by the keyboard sofware.
It may be trigger a plugin shortcut rather than global shortcut. -
@gstavi
Thanks for the response. I tried to find out the key code that was being generated, but with no luck.However, I have actually resolved my issue. It appears that notepad++ only intercepts the keys when being run as administrator. Not sure why that makes a difference, but I closed and re-opened with normal user privileges and it no longer intercepts it; ie I can change virtual desktops again.
-
For anyone who comes across this, I’ve written out a detailed solution in this StackOverflow question.
I know this post is old, but maybe it’ll help someone! :)
-
@Colin-Cuthbert said in How to stop Notepad++ intercepting back/forward keypresses?:
I have a Microsoft keyboard with specific “Back” and “Forward” keys, which are usually mapped to Back/Forward in web browsers, etc.
Notepad++ seems to be intercepting these key presses, and uses them to change to previous/next tab.
I got a mouse as a Christmas present this year. Obviously, I’ve had mice since I could walk, and I never thought I needed a new one. But my son thought I did. This mouse is very fancy, and has “forward” and “backward” buttons where they are actually usable (my previous mice sometimes had them, but they weren’t very friendly to use).
Long story short is that I tried these buttons out in Notepad++ and noticed that they change the active tab. Hmm, not very useful to me. So I set out to set them to useful functions. I decided on these two from the menu system:
So here’s the script I wrote, I call it
MouseForwardBackButtonsHook.py
:# -*- coding: utf-8 -*- from __future__ import print_function # references: # https://community.notepad-plus-plus.org/topic/13149 from Npp import * import inspect import os import platform from ctypes import (WinDLL, WINFUNCTYPE) from ctypes.wintypes import (HWND, INT, LPARAM, UINT, WPARAM) #------------------------------------------------------------------------------- user32 = WinDLL('user32') notepad_hwnd = user32.FindWindowW(u'Notepad++', None) assert notepad_hwnd LRESULT = LPARAM WndProcType = WINFUNCTYPE( LRESULT, # return type HWND, UINT, WPARAM, LPARAM # arguments ) running_32bit = platform.architecture()[0] == '32bit' SetWindowLong = user32.SetWindowLongW if running_32bit else user32.SetWindowLongPtrW SetWindowLong.restype = WndProcType SetWindowLong.argtypes = [ HWND, INT, WndProcType] GWL_WNDPROC = -4 SendMessage = user32.SendMessageW SendMessage.restype = LRESULT SendMessage.argtypes = [ HWND, UINT, WPARAM, LPARAM ] WM_APPCOMMAND = 0x319 APPCOMMAND_BROWSER_FORWARD = 2 # https://github.com/notepad-plus-plus/notepad-plus-plus/search?q=APPCOMMAND_BROWSER_FORWARD APPCOMMAND_BROWSER_BACKWARD = 1 # https://github.com/notepad-plus-plus/notepad-plus-plus/search?q=APPCOMMAND_BROWSER_BACKWARD FAPPCOMMAND_MASK = 0xF000 WM_COMMAND = 0x111 IDM_SEARCH_VOLATILE_FINDNEXT = 43014 IDM_SEARCH_VOLATILE_FINDPREV = 43015 def HIWORD(value): return (value >> 16) & 0xFFFF def GET_APPCOMMAND_LPARAM(lp): return HIWORD(lp) & ~FAPPCOMMAND_MASK #------------------------------------------------------------------------------- class MFBBH(object): def __init__(self): self.debug = True if 0 else False self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0] self.this_script_path_without_ext = inspect.getframeinfo(inspect.currentframe()).filename.rsplit('.', 1)[0] self.new_npp_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_npp_wnd_proc_hook) self.orig_npp_wnd_proc = SetWindowLong(notepad_hwnd, GWL_WNDPROC, self.new_npp_wnd_proc_hook_for_SetWindowLong) def new_npp_wnd_proc_hook(self, hwnd, msg, wParam, lParam): retval = True if msg == WM_APPCOMMAND: self.dprint('n++ WM_APPCOMMAND wParam={w}/0x{w:X} lParam={l}/0x{l:X}'.format(w=wParam, l=lParam)) if GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_FORWARD: self.dprint('APPCOMMAND_BROWSER_FORWARD') SendMessage(hwnd, WM_COMMAND, IDM_SEARCH_VOLATILE_FINDNEXT, 0) retval = False # set to False if we don't want further processing of this message elif GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_BACKWARD: self.dprint('APPCOMMAND_BROWSER_BACKWARD') SendMessage(hwnd, WM_COMMAND, IDM_SEARCH_VOLATILE_FINDPREV, 0) retval = False # set to False if we don't want further processing of this message if retval: retval = self.orig_npp_wnd_proc(hwnd, msg, wParam, lParam) return retval def print(self, *args, **kwargs): try: self.print_first except AttributeError: self.print_first = True if self.print_first: console.show() # this will put input focus in the PS console window, at the >>> prompt #console.clear() editor.grabFocus() # put input focus back into the editor window self.print_first = False d_tag = '<DBG>' if 'debug' in kwargs else '' if 'debug' in kwargs: del kwargs['debug'] print(self.__class__.__name__ + d_tag + ':', *args, **kwargs) def dprint(self, *args, **kwargs): # debug print function if self.debug: kwargs['debug'] = True self.print(*args, **kwargs) #------------------------------------------------------------------------------- # to run via another file, e.g., (user) startup.py, put these lines (uncommented and unindented) in that file: # import MouseForwardBackButtonsHook # STARTUP__mfbbh = MouseForwardBackButtonsHook.MFBBH() if __name__ == '__main__': try: STARTUP__mfbbh except NameError: STARTUP__mfbbh = MFBBH()
The “forward” button does the “find next” and the “backward” button does the “find previous”.
Information about setting up and using a PythonScript is HERE.
-
-
@Alan-Kilborn said in How to stop Notepad++ intercepting back/forward keypresses?:
The “forward” button does the “find next” and the “backward” button does the “find previous”.
I’ve decided that to me tying the functionalities this way doesn’t make sense. The “forward” button on the mouse is toward the top of the mouse, with the “backward” button closer to me. So, my thinking is that the further button should do the find-previous and the closer button should do the find-next. Thus, I’ve changed the code to swap the functionalities.
BTW, my fancy new mouse also has a horizontal scroll wheel, in addition to the normal vertical one:
When I try this h-wheel with Notepad++ (and other apps), I find that the scroll direction is the opposite of what I expect! (And that the scrolling isn’t “fast enough” but that’s a different thing). So, another script took care of “fixing” the h-scroll direction…for N++ at least (don’t see myself using h-scroll in other apps).
Probably installing the add-on s/w for the mouse allows me to configure such things; I don’t normally do that but with this mouse’s advanced features, I just might.