Community
    • Login

    Finding available shortcut keys (originally "Where's the 'New Window' command?")

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    53 Posts 7 Posters 5.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TBugReporterT
      TBugReporter
      last edited by guy038

      Let’s say that I have an instance of N++ running with dual panes and several file tabs open in each pane. If I get interrupted with a different task that needs a full screen view, I don’t want to shrink one of the panes for my current project because I’ll have a hard time getting them back how they were; instead I want to perform this new task using a completely new, separate window. I’ve been doing this with the awkward but semi-tolerable sequence of finding an open tab without any unsaved changes, right-clicking it, selecting “Open in New Instance”, and then closing the file in the new instance and opening the file(s) for the side project. I found https://community.notepad-plus-plus.org/topic/169/how-to-open-a-new-window , which suggests this is the way to do it, but can’t we have something easier and more intuitive?

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @TBugReporter
        last edited by

        @TBugReporter

        I’ve made an additional run menu entry using this $(NPP_FULL_FILE_PATH) -nosession -multiInst

        When using sessions, note that the last closed window writes the session configuration.

        TBugReporterT 1 Reply Last reply Reply Quote 1
        • TBugReporterT
          TBugReporter @Ekopalypse
          last edited by TBugReporter

          @Ekopalypse said in Where’s the “New Window” command?:

          $(NPP_FULL_FILE_PATH) -nosession -multiInst

          Okay, that works, but brings up another question - deciding on a keystroke to assign it to. I decided on Ctrl+Shift+N fairly quickly, but I can see that for power users, this could become difficult - and N++ provides very little help in that regard. I found https://community.notepad-plus-plus.org/topic/23749/list-of-free-keyboard-shortcuts/3 and related threads, but I’m not sure how to use the code given there, nor whether that code will show all assignments, built in assignments, customized assignments, plugin assignments, or some other subset(s). Given that some of the related threads are years old, I guess this is not on anyone’s priority list for converting it into a built-in N++ feature. :-)

          EkopalypseE 1 Reply Last reply Reply Quote 0
          • EkopalypseE
            Ekopalypse @TBugReporter
            last edited by

            @TBugReporter

            To run the scripts, you need to install the PythonScript plugin, create new scripts from its menu, and paste the appropriate code.
            The script you linked reads the current keyboard settings using the native shortcut mapper dialog that Npp uses, and Alan’s script basically outputs which shortcuts are still available.

            TBugReporterT 1 Reply Last reply Reply Quote 2
            • TBugReporterT
              TBugReporter @Ekopalypse
              last edited by TBugReporter

              Hmm. Your script works for me, but @Alan-Kilborn’s doesn’t. Of course, I’m (slightly) more interested in seeing the output from his; I can infer what his should be showing from the output of yours, but it’d be nice to know what’s going wrong.

              EDIT: Never mind. It does help if one actually takes the time to read the comments in the script. :-}

              EDIT #2: Weird that his script’s output can’t be saved except by copying it out of the tab that the script created and pasting it into another tab.

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @TBugReporter
                last edited by Alan Kilborn

                @TBugReporter said in Where’s the “New Window” command?:

                EDIT #2: Weird that his script’s output can’t be saved except by copying it out of the tab that the script created and pasting it into another tab.

                I think this is in reference to the ShortcutMapperUnassignedKeyCombos.py script in THIS THREAD 's Nov 21, 2022 4:40PM posting.

                The script used editor.setSavePoint() at the end to mark the tab as “saved”. Thus, at that point it is ineligible to actually be saved by Notepad++. However, if you add a character and then backspace it off again, you will be able to save the file.

                I marked it as saved for ease of closing – you don’t have to answer a prompt to save it when you try to close it, it just closes when you’re done viewing the data.

                1 Reply Last reply Reply Quote 2
                • TBugReporterT
                  TBugReporter
                  last edited by TBugReporter

                  @Alan-Kilborn said in Where’s the “New Window” command?:

                  The script used editor.setSavePoint()

                  I commented this line out - personal preference.

                  I wish I understood the internal references in these scripts, tho - I’d like to combine them to produce something like this:

                  				Ctrl	Ctrl+	Ctrl+	Ctrl+
                  		Alt	Alt+			Alt	Alt+
                  Raw	Shift		Shift		Shift		Shift	Key
                  ========================================================================
                  C	_	_	_	_	_	_	_	Esc
                  A	_	R	_	_	_	_	_	F1
                  S	S	_	_	S	_	_	_	F2
                  S	S	R	_	S	S	S	S	F3
                  S	S	F	_	_	_	_	_	F4
                  R	_	_	_	_	_	_	_	F5
                  P	P	R	_	P	_	_	_	F6
                  S	_	_	_	_	_	_	_	F7
                  V	_	_	_	_	_	_	_	F8
                  _	_	_	_	_	_	_	_	F9
                  _	_	_	_	_	_	_	_	F10
                  V	_	_	_	_	_	_	_	F11
                  V	_	_	_	_	_	_	_	F12
                  0	0	_	_	P	_	_	_	~
                  (I don't understand why the above key is listed as ~ instead of `, but I can live with it.)
                  0	0	V	V	S	S	P	_	1
                  0	0	V	V	S	S	_	_	2
                  0	0	V	V	S	S	_	_	3
                  0	0	V	V	S	S	_	_	4
                  0	0	V	V	S	S	_	_	5
                  0	0	V	V	_	_	_	_	6
                  0	0	V	V	_	_	_	_	7
                  0	0	V	V	_	_	_	_	8
                  0	0	_	_	_	_	_	_	9
                  0	0	V	V	S	S	_	_	0
                  0	0	_	_	_	_	_	_	-
                  0	0	_	_	_	_	_	_	=
                  C	C	C	_	C	C	_	_	Backspace
                  C	C	_	_	C	_	_	_	INS
                  C	C	C	C	C	C	_	_	Home
                  C	C	P	C	V	V	P	_	Page up
                  @	_	_	_	C	_	_	_	Num /
                  @	_	_	_	C	_	_	_	Num -
                  @	_	_	_	_	_	_	_	Num *
                  ========================================================================
                  				Ctrl	Ctrl+	Ctrl+	Ctrl+
                  		Alt	Alt+			Alt	Alt+
                  Raw	Shift		Shift		Shift		Shift	Key
                  ========================================================================
                  C	C	@	@	V	V	0	0	Tab
                  0	0	_	_	E	E	_	_	Q
                  0	0	_	_	F	F	_	_	W
                  0	0	_	_	P	P	P	_	E
                  0	0	_	_	F	R	V	P	R
                  0	0	_	_	PC	FP	P	_	T
                  0	0	_	_	C	_	_	_	Y
                  0	0	E	E	E	E	E	E	U
                  0	0	_	_	E	_	S	_	I
                  0	0	_	_	F	_	_	P	O
                  0	0	_	_	C	M	_	P	P
                  0	0	_	_	C	C	_	_	[
                  0	0	_	_	C	C	_	_	]
                  0	0	_	_	C	C	_	_	\
                  C	C	_	_	C	C	_	_	DEL
                  C	C	C	C	C	C	_	_	End
                  C	C	P	C	V	V	P	_	Page down
                  @	_	_	_	V	_	_	_	Numpad 7
                  @	_	_	_	V	_	_	_	Numpad 8
                  @	_	_	_	V	_	_	_	Numpad 9
                  @	_	_	_	C	_	_	_	Num +
                  0	0	_	_	C	_	_	P	A
                  0	0	_	M	F	F	F	_	S
                  0	0	_	_	C	_	P	_	D
                  0	0	_	_	S	S	V	V	F
                  0	0	_	_	S	_	P	_	G
                  0	0	V	_	S	_	_	P	H
                  0	0	P	P	E	_	P	_	J
                  0	0	_	_	E	E	_	_	K
                  0	0	_	_	C	C	V	P	L
                  0	0	_	_	_	_	_	_	;
                  0	0	_	_	_	_	_	_	'
                  C	C	_	_	E	_	E	E	Enter
                  (N++ apparently doesn't distinguish between the two Enter keys most keyboards have.)
                  @	_	_	_	V	_	_	_	Numpad 4
                  @	_	_	_	V	_	_	_	Numpad 5
                  @	_	_	_	V	_	_	_	Numpad 6
                  ========================================================================
                  				Ctrl	Ctrl+	Ctrl+	Ctrl+
                  		Alt	Alt+			Alt	Alt+
                  Raw	Shift		Shift		Shift		Shift	Key
                  ========================================================================
                  0	0	_	_	C	C	_	_	Z
                  0	0	_	_	C	C	P	P	X
                  0	0	E	_	C	_	P	P	C
                  0	0	_	_	C	_	P	_	V
                  0	0	_	_	S	_	S	P	B
                  0	0	_	_	F	R	_	_	N
                  0	0	_	_	S	_	P	P	M
                  0	0	_	_	_	_	_	_	,
                  0	0	_	_	_	_	_	_	.
                  0	0	_	_	C	C	_	_	/
                  C	C	E	C	C	E	M	_	Up
                  @	_	_	_	V	_	_	_	Numpad 1
                  @	_	_	_	V	_	_	_	Numpad 2
                  @	_	_	_	V	_	_	_	Numpad 3
                  @	@	_	_	E	E	E	_	Spacebar
                  C	C	_	C	C	C	_	_	Left
                  C	C	E	C	C	E	M	_	Down
                  C	C	_	C	C	C	_	_	Right
                  @	_	_	_	_	_	_	_	Numpad 0
                  @	_	_	_	_	_	_	_	Num .
                  ========================================================================
                  				Ctrl	Ctrl+	Ctrl+	Ctrl+
                  		Alt	Alt+			Alt	Alt+
                  Raw	Shift		Shift		Shift		Shift	Key
                  ========================================================================
                  0 = not a Shortcut key combination
                  @ = not usually a Shortcut key combination, but can be used as one
                  _ = Shortcut key is unassigned
                  F = Shortcut key is assigned to a File command
                  E = Shortcut key is assigned to an Edit command
                  4 = Shortcut key is assigned to a Format command
                  S = Shortcut key is assigned to a Search command
                  V = Shortcut key is assigned to a View command
                  L = Shortcut key is assigned to a Lang command
                  T = Shortcut key is assigned to a Setting command
                  X = Shortcut key is assigned to the Execute command
                  W = Shortcut key is assigned to a Window command
                  A = Shortcut key is assigned to an About command
                  M = Shortcut key is assigned to a Macro
                  R = Shortcut key is assigned to a Run command
                  P = Shortcut key is assigned to a Plugin command
                  C = Shortcut key is assigned to a Scintilla command
                  	(multiple characters indicate a conflict)
                  
                  Alan KilbornA 1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn @TBugReporter
                    last edited by

                    @TBugReporter said in Where’s the “New Window” command?:

                    I commented this line out - personal preference.

                    Sure, scripts posted here are encouraged to be modified to suit individual desires!


                    One thing I struggled a bit with in the script under discussion was the output format. Again, if mine isn’t liked, go forward with modifying it so that you like it. Although I must say I took a look at your desired format and I don’t really understand it.

                    TBugReporterT 1 Reply Last reply Reply Quote 1
                    • TBugReporterT
                      TBugReporter @Alan Kilborn
                      last edited by TBugReporter

                      @Alan-Kilborn said in Where’s the “New Window” command?:

                      if mine isn’t liked, go forward with modifying it so that you like it.

                      I’m trying, but I want to combine your script with the one by @Ekopalypse, to eliminate the intermediate steps - and I literally haven’t gotten past the first lines of his. What is it that’s being imported? Is there any documentation (other than the N++ source itself) as to how much of the rest is pulled from these imports vs. how much is specific to the script?

                      Although I must say I took a look at your desired format and I don’t really understand it.

                      Did you scroll to the bottom? Most of it is explained there. (That’s where I would expect the explanation to be in the processed output, but I suppose I should have led with that for the post. I didn’t realize it would be shown as a scrolling subsection.)


                      Also, getting back to the original intent of this thread…

                      @Ekopalypse said in Where’s the “New Window” command?:

                      I’ve made an additional run menu entry using this $(NPP_FULL_FILE_PATH) -nosession -multiInst

                      When using sessions, note that the last closed window writes the session configuration.

                      I’ve found a peculiar behavior using this. To reproduce:

                      1. Invoke this command to create a new window.
                      2. In the new window, use the Recent Files list to open a few files.
                      3. Close the second window.
                      4. Invoke the command again from the first window.
                      5. Inspect the Recent Files list from this third window.

                      Result: The files you opened in the second window are missing from the Recent Files list of the third (and subsequent) window(s). To get a full Recent Files list, I have to close the other window(s), close the first window, restart N++, and invoke New Window again.

                      (I haven’t tried creating new files or opening files not in Recent from these subsequent windows; I don’t want to risk losing track of what’s currently in that list.)

                      EkopalypseE Alan KilbornA 3 Replies Last reply Reply Quote 0
                      • EkopalypseE
                        Ekopalypse @TBugReporter
                        last edited by

                        @TBugReporter

                        The imports are needed to get access to the notepad++ (notepad) and scintilla (editor) objects, and for interaction with calls to the Windows library (ctypes).
                        All of these objects are required.
                        If you are concerned about re-importing something that is already used in another script, there is no reason to do so, as Python stores the imported objects internally in a dictionary and skips this step if the object is already loaded.

                        We have to use another thread to start the shortcut mapper dialog because it blocks, otherwise it would wait until the dialog is closed and then we would not be able to collect all the information from the dialog.

                        The easiest way to merge this with another script would be to rename the main function to something else, get rid of the notepad.new and editor.setText calls and then return the list of shortcuts.

                        TBugReporterT 1 Reply Last reply Reply Quote 1
                        • TBugReporterT
                          TBugReporter @Ekopalypse
                          last edited by TBugReporter

                          @Ekopalypse said in Where’s the “New Window” command?:

                          All of these objects are required.

                          I figured that; I just wanted to get a better understanding of exactly why they’re required. (I never want to become that horrible programmer who blindly copies from other programs without taking the time to understand what the code is doing.)

                          I don’t know if it’s differences in programming style, or just the fact that your script is doing all the heavy lifting, but @Alan-Kilborn’s is much easier for me to wrap my head around.

                          We have to use another thread

                          Okay, that makes sense.

                          The easiest way to merge this with another script would be to rename the main function to something else, get rid of the notepad.new and editor.setText calls and then return the list of shortcuts.

                          Actually, I probably want to keep them, but just massage the retrieved data differently than your script does - iterate over shortcuts, but build the output document non-sequentially. I’ll also need access to which tab and (for the “Main menu” tab) which Category each data item came from.

                          EkopalypseE Alan KilbornA 2 Replies Last reply Reply Quote 1
                          • Alan KilbornA
                            Alan Kilborn @TBugReporter
                            last edited by

                            @TBugReporter said in Where’s the “New Window” command?:

                            Although I must say I took a look at your desired format and I don’t really understand it.

                            Did you scroll to the bottom?

                            I didn’t! OK, it is clearer now.

                            Mendella ReplacementM 1 Reply Last reply Reply Quote 0
                            • Alan KilbornA
                              Alan Kilborn @TBugReporter
                              last edited by

                              @TBugReporter said in Where’s the “New Window” command?:

                              I’ve found a peculiar behavior using this. To reproduce:

                              Invoke this command to create a new window.
                              In the new window, use the Recent Files list to open a few files.
                              Close the second window.
                              Invoke the command again from the first window.
                              Inspect the Recent Files list from this third window.

                              Result: The files you opened in the second window are missing from the Recent Files list of the third (and subsequent) window(s). To get a full Recent Files list, I have to close the other window(s), close the first window, restart N++, and invoke New Window again.

                              Something to remember when using multiple instances is that they don’t communicate well with each other. Another example is if you go into the Preferences and make a change, only that instance will know about the change. And, unless the instance where you made the change is exited last of all the instances, the change won’t be there when you run Notepad++ again. The reason for this is rather simple: When an instance of N++ exits, it writes its settings to disk. If another instance is still running, again, when it exits, it writes its settings to disk. If the settings happen to be different, the settings for the last one to write are preserved for the next clean run of the program.

                              1 Reply Last reply Reply Quote 1
                              • EkopalypseE
                                Ekopalypse @TBugReporter
                                last edited by

                                @TBugReporter

                                I never want to become that horrible programmer who blindly copies from other programs without taking the time to understand what the code is doing.

                                Very commendable!

                                … is much easier for me to wrap my head around.

                                This is pretty basic Windows programming stuff, I’d say, but if you’re new to Windows programming, then let me briefly explain how this usually works.

                                Whenever you want to interact with a GUI application in Windows, you need its ID, the HWND that is the handle of a window. You can get this by using user32.dll functions such as FindWindow and FindWindowEx.
                                To communicate with the window, use functions like SendMessage.
                                For example, TCM_GETITEMCOUNT is a message sent to a SysTabControl32 to query the number of available tabs.

                                BGM_GETROWS is defined by Notepad++ itself.

                                SetForegroundWindow is used to ensure that the following simulated keystrokes (keybd_event) are sent to the application they are intended for.

                                1 Reply Last reply Reply Quote 1
                                • Alan KilbornA
                                  Alan Kilborn @TBugReporter
                                  last edited by

                                  @TBugReporter said in Where’s the “New Window” command?:

                                  I don’t know if it’s differences in programming style, or just the fact that your (Eko) script is doing all the heavy lifting, but @Alan-Kilborn’s is much easier for me to wrap my head around.

                                  This is totally because Eko’s script IS doing the “heavy lifting”. My script is simple in comparison.

                                  When you see ctypes in a Python program, expect “heavy lifting”, “magic”, and “pixie dust” to be on display. :-)

                                  EkopalypseE 1 Reply Last reply Reply Quote 2
                                  • EkopalypseE
                                    Ekopalypse @Alan Kilborn
                                    last edited by

                                    @Alan-Kilborn said in Where’s the “New Window” command?:

                                    When you see ctypes in a Python program, expect “heavy lifting”, “magic”, and “pixie dust” to be on display. :-)

                                    :-D and it works only during full moon and when you dance around a fire :-D

                                    TBugReporterT 1 Reply Last reply Reply Quote 4
                                    • TBugReporterT
                                      TBugReporter @Ekopalypse
                                      last edited by TBugReporter

                                      I’m dancing as fast as I can (meaning “as my spare time allows”), but I’ve hit a snag. I want my script’s output to read the name of the tab where a given shortcut was found, but the descriptions I’ve found of how to do this for other languages either assume the existence of library functions in that language which I can’t find source code to, or else they dive headfirst into deep voodoo without a life jacket. :-}

                                      I’m guessing I have to do something like

                                      user32.SendMessageW(sys_tab_hwnd, TCM_GETITEMCOUNT, 0, 0)
                                      

                                      but send a different message, and figure out how to read the response. Any chance one of you could point me in a less random direction?

                                      Also, given that this thread has drifted so far away from the original topic, is there any way I can change its title?

                                      EkopalypseE 2 Replies Last reply Reply Quote 1
                                      • EkopalypseE
                                        Ekopalypse @TBugReporter
                                        last edited by

                                        @TBugReporter

                                        I can take a look today after work (in 6-7 hours).

                                        1 Reply Last reply Reply Quote 0
                                        • guy038G
                                          guy038
                                          last edited by guy038

                                          Hello, @tbugreporter ,

                                          Regarding specifically the title changes, which title would you like to see ? As a moderator, I can modify it easily !

                                          BR

                                          guy038

                                          TBugReporterT 1 Reply Last reply Reply Quote 1
                                          • EkopalypseE
                                            Ekopalypse @TBugReporter
                                            last edited by

                                            @TBugReporter

                                            Found the time to try it out during my lunch break.

                                            TCM_GETITEMW = (TCM_FIRST + 60)  # get the current tab message
                                            TCIF_TEXT = 1  # flag to specify that we are only interested in pszText
                                            
                                            # define the storage that will contain the requested information.
                                            class TCITEM(ctypes.Structure):
                                                _fields_ = [('mask',        wintypes.UINT),
                                                            ('dwState',     wintypes.DWORD),
                                                            ('dwStateMask', wintypes.DWORD),
                                                            ('pszText',     wintypes.LPWSTR),
                                                            ('cchTextMax',  wintypes.INT),
                                                            ('iImage',      wintypes.INT),
                                                            ('lParam',      wintypes.LPARAM)]
                                            
                                            
                                            pszText = ctypes.create_unicode_buffer(260)  # create a buffer to hold the tab text
                                            tcitem = TCITEM()  # create an instance
                                            tcitem.mask = TCIF_TEXT  # specify that we want to read the pszText field
                                            tcitem.pszText = addressof(pszText)  # points to the tab text buffer 
                                            tcitem.cchTextMax = len(pszText)  # length of buffer
                                            pITEM = byref(tcitem)  # pointer to the concrete struct TCITEM 
                                            
                                            # within the for loop call
                                            found = user32.SendMessageW(sys_tab_hwnd, TCM_GETITEMW, tab, pITEM)
                                            if found:
                                            	print(tcitem.pszText)
                                            

                                            Seems to work, let me know if anything is unclear.

                                            TBugReporterT 1 Reply Last reply Reply Quote 2
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors