• Login
Community
  • Login

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

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
53 Posts 7 Posters 7.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.
  • T
    TBugReporter
    last edited by TBugReporter Jan 1, 2023, 9:34 PM Jan 1, 2023, 9:33 PM

    @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)
    
    A 1 Reply Last reply Jan 2, 2023, 1:59 AM Reply Quote 1
    • A
      Alan Kilborn @TBugReporter
      last edited by Jan 2, 2023, 1:59 AM

      @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.

      T 1 Reply Last reply Jan 2, 2023, 8:19 AM Reply Quote 1
      • T
        TBugReporter @Alan Kilborn
        last edited by TBugReporter Jan 2, 2023, 9:06 AM Jan 2, 2023, 8:19 AM

        @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.)

        E A 3 Replies Last reply Jan 2, 2023, 9:28 AM Reply Quote 0
        • E
          Ekopalypse @TBugReporter
          last edited by Jan 2, 2023, 9:28 AM

          @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.

          T 1 Reply Last reply Jan 2, 2023, 10:08 AM Reply Quote 1
          • T
            TBugReporter @Ekopalypse
            last edited by TBugReporter Jan 2, 2023, 10:09 AM Jan 2, 2023, 10:08 AM

            @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.

            E A 2 Replies Last reply Jan 2, 2023, 12:06 PM Reply Quote 1
            • A
              Alan Kilborn @TBugReporter
              last edited by Jan 2, 2023, 11:30 AM

              @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.

              M 1 Reply Last reply Jan 13, 2023, 4:26 PM Reply Quote 0
              • A
                Alan Kilborn @TBugReporter
                last edited by Jan 2, 2023, 11:38 AM

                @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
                • E
                  Ekopalypse @TBugReporter
                  last edited by Jan 2, 2023, 12:06 PM

                  @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
                  • A
                    Alan Kilborn @TBugReporter
                    last edited by Jan 2, 2023, 12:12 PM

                    @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. :-)

                    E 1 Reply Last reply Jan 2, 2023, 12:17 PM Reply Quote 2
                    • E
                      Ekopalypse @Alan Kilborn
                      last edited by Jan 2, 2023, 12:17 PM

                      @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

                      T 1 Reply Last reply Jan 6, 2023, 6:52 AM Reply Quote 4
                      • T
                        TBugReporter @Ekopalypse
                        last edited by TBugReporter Jan 6, 2023, 7:02 AM Jan 6, 2023, 6:52 AM

                        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?

                        E 2 Replies Last reply Jan 6, 2023, 9:48 AM Reply Quote 1
                        • E
                          Ekopalypse @TBugReporter
                          last edited by Jan 6, 2023, 9:48 AM

                          @TBugReporter

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

                          1 Reply Last reply Reply Quote 0
                          • G
                            guy038
                            last edited by guy038 Jan 6, 2023, 10:04 AM Jan 6, 2023, 10:02 AM

                            Hello, @tbugreporter ,

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

                            BR

                            guy038

                            T 1 Reply Last reply Jan 7, 2023, 2:57 AM Reply Quote 1
                            • E
                              Ekopalypse @TBugReporter
                              last edited by Jan 6, 2023, 11:08 AM

                              @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.

                              T 1 Reply Last reply Jan 7, 2023, 7:18 AM Reply Quote 2
                              • T
                                TBugReporter @guy038
                                last edited by Jan 7, 2023, 2:57 AM

                                @guy038:

                                which title would you like to see ?

                                How about

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

                                As a moderator, I can modify it easily !

                                TYVM!

                                @Ekopalypse:

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

                                Yes, that looks like the info I needed; now I just have to add it to the script.

                                TYVM to you too!

                                1 Reply Last reply Reply Quote 1
                                • T
                                  TBugReporter @Ekopalypse
                                  last edited by Jan 7, 2023, 7:18 AM

                                  @Ekopalypse

                                  My latest sticking point:

                                  NameError: global name 'byref' is not defined
                                  
                                  R 1 Reply Last reply Jan 7, 2023, 9:01 AM Reply Quote 0
                                  • R
                                    rdipardo @TBugReporter
                                    last edited by Jan 7, 2023, 9:01 AM

                                    NameError: global name 'byref' is not defined
                                    

                                    Try ctypes.byref instead.

                                    1 Reply Last reply Reply Quote 1
                                    • T
                                      TBugReporter
                                      last edited by Jan 9, 2023, 6:27 AM

                                      Here’s a question from the “newless cluebie to Python” department:

                                      I’m currently struggling with errors like

                                      NameError: global name 'my_new_variable' is not defined
                                      

                                      I read that there’s a “global” statement that can help, but it doesn’t seem to work for me. Exactly where should this go? Or, is there another way I can rearrange the code that will avoid this?

                                      E 1 Reply Last reply Jan 9, 2023, 9:32 AM Reply Quote 0
                                      • E
                                        Ekopalypse @TBugReporter
                                        last edited by Jan 9, 2023, 9:32 AM

                                        @TBugReporter

                                        In the function in which it is used, suppose there is a code like this

                                        x = 42
                                        y = {'x': 42}
                                        
                                        def main():
                                            global x
                                            x += 1
                                            y['x'] += 1
                                            print(x)
                                            print(y)
                                            
                                        main()
                                        

                                        x needs to be defined as global, while it is not necessary for y, because it is a dict.

                                        1 Reply Last reply Reply Quote 2
                                        • T
                                          TBugReporter
                                          last edited by Jan 10, 2023, 11:48 PM

                                          The pest is back! 😁 (I thank you in advance for your patience with me.)

                                          • Can I use PythonScript to display a Windows MessageBox? Can I create my own custom dialogs in Windows style?

                                          • How can I prematurely end my script (if something weird happens)? I found sys.exit(), but this apparently terminates all of Notepad++ along with the script.

                                          P T 2 Replies Last reply Jan 11, 2023, 12:31 AM Reply Quote 1
                                          16 out of 53
                                          • First post
                                            16/53
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors