<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PythonScript Toggleable Script?]]></title><description><![CDATA[<p dir="auto">Hello everyone, I was wondering if it is possible (or deeply time consuming) to make a toggleable PythonScript in Notepad++. Notepad++ has the useful feature of holding “Shift” + “Alt” to go into Column text select mode which is useful for making changes to data files such as CSVs. I would like to create a PythonScript that can be toggled on/off for activating column text select mode. Preferably as a button using the Customize Toolbar plugin. Thank you in advance for any assistance!</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/22890/pythonscript-toggleable-script</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 01:44:52 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/22890.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 22 Apr 2022 14:41:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 17:28:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> You’re exactly correct, this has been a great learning experience for me regarding Notepad++ plugin development. I  plan to continue improving my current plugins and write new ones. Once again thank you <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@Alan-Kilborn</a>  and <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a>  for pointing me in the right direction, you’ve been helped a great deal!   : - )</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76512</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76512</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Thu, 28 Apr 2022 17:28:13 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 17:10:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> said in <a href="/post/76504">PythonScript Toggleable Script?</a>:</p>
<blockquote>
<p dir="auto">I can be very picky trying to get a program to behave exactly how I want</p>
</blockquote>
<p dir="auto">Sure, I understand this; I have Notepad++ heavily customized with scripts to have it behave how <em>I</em> want.  But…when you do something like this, you have to understand the limitations of the environment you are working within, in order to “not” overstep your bounds.</p>
<p dir="auto">Using things which hold keys down, writing infinite loops,  running multiple scripts before one is finished…all of these are bad ideas in the context of what PythonScript aims to provide to Notepad++ users.</p>
<p dir="auto">I really don’t know how to provide advice on what to <em>not</em> do, though, until you do it and post here asking for advice on how to solve encountered problems. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76511</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76511</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 28 Apr 2022 17:10:09 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:48:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@peterjones</a> Thank you, I do very much appreciate all of your help. It has helped greatly, I can be very picky trying to get a program to behave exactly how I want, my apologies for that, I understand it can be too much of a time sink and sometimes impossible.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76504</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76504</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:48:35 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:48:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a></p>
<p dir="auto">In case you don’t know which I mean by simplest, here is the version I have saved as <code>SelectionToRectangle.py</code> in my instance.  I am actually going to use that in my workflow occasionally, because I am sometimes on a linux box and remote-desktop-connecting into my windows laptop, and the ALT key doesn’t transmit properly, so previously I wasn’t able to column selection; now I have a simple way to easily switch a normal selection to column selection, without using the ALT key.</p>
<pre><code># encoding=utf-8
"""
Derived from 22890-simplest.py, in response to https://community.notepad-plus-plus.org/topic/22890/

This is the simplest paradigm for converting a stream (normal) selection to rectangular (column):
1) Click or arrow to where you want to start selecting
2) Shift+Click or Shift+arrow to get to the end of the selection (ie, do a normal selection)
3) Run this script to convert the selection from STREAM to rectangle and refresh the screen automatically to see it
"""
from Npp import notepad, editor, SELECTIONMODE, STATUSBARSECTION
editor.setSelectionMode( SELECTIONMODE.RECTANGLE )
notepad.activateFile(notepad.getCurrentFilename()) # use the activateFile() command to refresh UI; otherwise, it doesn't _look_ like column/rectangle select)
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/76503</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76503</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:47:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a></p>
<p dir="auto">Did you not try my scripts?  Because both ⇅ and the “simplest” will work, whether you use the keyboard or clicking and dragging.  With ⇅ , click where you want to start the selection, then run the script, then click-and-drag to the end of the selection, then run the script, <strong>and it will convert that click-and-drag-selection to rectangle</strong>.  With the <img src="https://camo.nodebb.org/ce08f60e7ed23bf9ab35c29d5a640e27910871b0?url=https%3A%2F%2Fcommunity.notepad-plus-plus.org%2Fassets%2Fuploads%2Ffiles%2F1651087909122-a1fa538a-4877-4745-ae14-de90d27d0b9d-image.png" alt="" class=" img-fluid img-markdown" /> “simplest” script, just click-and-drag your selection, then run the script, <strong>and it will convert that click-and-drag-selection to rectangle</strong>.</p>
<p dir="auto">The infinite loop will <strong>not</strong> work for you.  Stop trying to make it work.  It is the wrong design.  Every one of the problems you have run across has proven that to everyone (except you, who seems unwilling to accept an alternate solution that works better).</p>
<p dir="auto">I have already written multiple scripts, and shown you how it works, in words and in video.  If you are unwilling to go this route, I cannot help you beyond this.  I am sorry.  Good luck.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76502</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76502</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:47:55 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:40:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@PeterJones</a> The reason for the infinite loop is that I want to make the script act like a toggle that works for not only arrow keys but also clicking and dragging for selection. I have the following statement in my infinite loop (among others):</p>
<p dir="auto">editor.setSelectionMode(SELECTIONMODE.RECTANGLE)</p>
<p dir="auto">This is the only way to be able to click and drag rectangle select persistently, it works for arrow key selection as well, only thing is if it is not in an infinite loop then that functionality no longer works.</p>
<p dir="auto">Edit: Is there a function that can check if another PythonScript is being launched? That would be a good way to break the loop.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76501</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76501</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:40:16 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:32:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> said in <a href="/post/76498">PythonScript Toggleable Script?</a>:</p>
<blockquote>
<p dir="auto">I’m wondering how I can make it so that the user can break the infinite loop in my script by clicking on the button for the script again</p>
</blockquote>
<p dir="auto">By writing it without an infinite loop.  The three line script I supplied is all you need to be able to easily convert a normal selection to a rectangle/column selection after the selection is made.  Or the ⇅ script I showed you will allow a toggle-on/toggle-off <em>without requiring an infinite loop</em>.</p>
<p dir="auto">I cannot say it any more plainly.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76500</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76500</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:32:33 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:30:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> said in <a href="/post/76498">PythonScript Toggleable Script?</a>:</p>
<blockquote>
<p dir="auto">how I can make it so that the user can break the infinite loop in my script</p>
</blockquote>
<p dir="auto">Possible solution: Don’t put an infinite loop in the script in the first place?</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76499</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76499</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:30:51 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 15:28:41 GMT]]></title><description><![CDATA[<p dir="auto">Okay, going back to what the this thread was originally about, my toggle function is not working as I thought it would. If I go to click it to toggle it off, I get the following messagebox text:</p>
<p dir="auto">“Another script is currently running. Running two scripts at the same time could produce unpredictable results, and is therefore disabled.”</p>
<p dir="auto">I’m wondering how I can make it so that the user can break the infinite loop in my script by clicking on the button for the script again, essentially making it toggleable. Anyone got an idea? It would be much appreciated.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76498</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76498</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Thu, 28 Apr 2022 15:28:41 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Thu, 28 Apr 2022 12:04:49 GMT]]></title><description><![CDATA[<p dir="auto">So…all this is great, but I really don’t see an advantage to it (the whole concept), and this is why:</p>
<ul>
<li>
<p dir="auto">if you’re a dedicated keyboardist, you’d have to dive for the mouse in order to hit the toolbar button to change the mode, spoiling being dedicated to the keyboard (where you could just add Alt to your Shift+arrows movement to get a column block).</p>
</li>
<li>
<p dir="auto">if you’re not in love with keyboard-only actions, use the mouse to select text via click and drag; if you start this as a stream selection, you can add a press of Alt to it while you are dragging (can even just tap-n-release Alt) in order to change the selection to a column block type.</p>
</li>
</ul>
<p dir="auto">But…people will want what they will want, and that’s ok. :-)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76480</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76480</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Thu, 28 Apr 2022 12:04:49 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 20:01:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a></p>
<p dir="auto">So here are some example screenshot-videos of using the two</p>
<p dir="auto">I assigned the ⇅ button to the “toggle” (the post that has the script with <code>"alternate paradigm"</code> in the comments).</p>
<p dir="auto">For the ⇅ , I record the sequence</p>
<ol>
<li>start selection with a click</li>
<li>click the ⇅ button to start the rectangle/column selection</li>
<li>end selection with a click</li>
<li>click the ⇅ button to end the rectangle/column selection, and convert it to visually be a rectangle selection</li>
<li>start new selection with a click</li>
<li>click the ⇅ button to start the rectangle/column selection</li>
<li>extend new selection with SHIFT+arrow</li>
<li>click the ⇅ button to end the rectangle/column selection, and convert it to visually be a rectangle selection<br />
<img src="https://camo.nodebb.org/851602e48e1b68a51dcc044b923e769d5ddafbf5?url=https%3A%2F%2Fi.imgur.com%2FHKYbqxq.gif" alt="" class=" img-fluid img-markdown" /></li>
</ol>
<p dir="auto">You will see that the status bar reflects the correct state of when you have clicked ⇅ the first time (so the script is in “active” mode), and that it clears itself when you do the second ⇅ (so it’s converted)</p>
<p dir="auto">---------------------</p>
<p dir="auto"><img src="/assets/uploads/files/1651087909122-a1fa538a-4877-4745-ae14-de90d27d0b9d-image.png" alt="a1fa538a-4877-4745-ae14-de90d27d0b9d-image.png" class=" img-fluid img-markdown" /> I assigned the other button to the “simplest” – the three-line version shown in my later post.</p>
<p dir="auto">For the <img src="/assets/uploads/files/1651087909122-a1fa538a-4877-4745-ae14-de90d27d0b9d-image.png" alt="a1fa538a-4877-4745-ae14-de90d27d0b9d-image.png" class=" img-fluid img-markdown" /> , I recorded the sequence</p>
<ol>
<li>start the selection with a click</li>
<li>extend the selection with SHIFT+ARROW</li>
<li>convert the selection to rectangular by calling the 🛈 script<br />
<img src="https://camo.nodebb.org/44a87c24c140461ecffba9ababe8fb23584d71d5?url=https%3A%2F%2Fi.imgur.com%2F9rcby1x.gif" alt="" class=" img-fluid img-markdown" /></li>
</ol>
<p dir="auto">This doesn’t show the status, because the button is a one-time thing, not a “in the active mode” thing.</p>
<p dir="auto">Either should work.  Both avoid any low-level programming or callbacks – they just use standard, simple PythonScript calls.</p>
<p dir="auto">The second has the benefit of being really simple, and doesn’t even need to save state.  If you or your user want to convert a normal selection to rectangle, just click the button after making the selection.  Don’t need to worry about the status bar. Easiest to use. Easiest to maintain.  You can always decide to use that to change any stream selection into a rectangle, whether you were thinking “I need to select a rectangle” or not.  Fewer clicks.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76463</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76463</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 27 Apr 2022 20:01:47 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 18:53:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> ,</p>
<p dir="auto">Since it apparently confused others, I will be more explicit about the example I gave above: it has a slightly different usage model than your explain seems to imply.  If we read your usage model correctly, you want to have this script toggle the “column” mode, and you are then using shift+arrows to make the block selection live.</p>
<p dir="auto">In my script, I figured: if you don’t want to faff around with ALT, then also don’t faff around with SHIFT.  My usage model (for the script shown above) is “run script to start the column/rectangle selection; move cursor (either normal arrow or just click, since you’re already clicking the script on the toolbar); run script to end column/rectangle selection and then refresh the display so it looks like a column selection”.</p>
<p dir="auto">But if you or your users insist on holding down the SHIFT, my script (above) will also work for that – it will look like a normal selection until the end when you run the script the second time, then it will convert the selection from normal to rectangular.</p>
<p dir="auto">Which means, really, the script could be simplified to just run</p>
<pre><code>from Npp import editor, notepad, SELECTIONMODE
editor.setSelectionMode(SELECTIONMODE.RECTANGLE)
notepad.activateFile(notepad.getCurrentFilename())
</code></pre>
<p dir="auto">Then the usage model would be “1) move your cursor to the start of where you want to select (via mouse or keyboard); 2) SHIFT+arrow or SHIFT+click to draw a normal selection; 3) run the script to convert the normal selection to a rectangle/column selection”.  Fewer clicks.  Call the script “convert active selection to rectangle” and be done with it.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76457</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76457</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 27 Apr 2022 18:53:59 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 18:20:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@peterjones</a> said in <a href="/post/76448">PythonScript Toggleable Script?</a>:</p>
<blockquote>
<p dir="auto">editor.getSelectionMode() which returns a 1 (IIRC) for rectangle</p>
</blockquote>
<p dir="auto">That is indeed correct, and this is also available returning True/False:  <code>editor.selectionIsRectangle()</code></p>
]]></description><link>https://community.notepad-plus-plus.org/post/76453</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76453</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Wed, 27 Apr 2022 18:20:41 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 17:50:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@peterjones</a> Thank you, I saw your reply to my other post also. My apologies, I’ll delete it and refrain from that in the future.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76451</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76451</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Wed, 27 Apr 2022 17:50:43 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 17:49:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> ,</p>
<p dir="auto">That’s what I thought at first.  But when I triggered the refresh (the activate file line), it updated and showed that it really did change what was shown to be  the rectangle – that’s why I included that line in the script, and included comments to say it was needed to get it to show it’s a rectangle.</p>
<p dir="auto">You can also tell that it was rectangle by just doing the editor.getSelectionMode() which returns a 1 (IIRC) for rectangle, or just do the copy then paste in the new location, and see it only grabbed the rectangle, not the full lines.  Actually, I first saw it was working when I swapped to another tab and then back, and saw it was suddenly a rectangle instead of the stream it looked like.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76448</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76448</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 27 Apr 2022 17:49:44 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 16:31:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@peterjones</a> the statement:</p>
<p dir="auto">editor.setSelectionMode( SELECTIONMODE.RECTANGLE )</p>
<p dir="auto">doesn’t seem to work, I tested it in a simple script with nothing else going on and this makes no changes to the selection mode, I’ve no idea why.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76444</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76444</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Wed, 27 Apr 2022 16:31:59 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Wed, 27 Apr 2022 15:53:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> ,</p>
<p dir="auto">Your paradigm is <a href="#" title="Broken As Designed">BAD</a> and causing you problems.</p>
<p dir="auto">Try this script out for size:</p>
<pre><code># encoding=utf-8
"""in response to https://community.notepad-plus-plus.org/topic/22890/ and 22919

alternate paradigm
"""
from Npp import notepad, editor, SELECTIONMODE, STATUSBARSECTION

try:
    columnSelectMode
    startPos
    endPos
except NameError:
    #console.show()
    console.write('initialize toggle mode for the first time\n')
    columnSelectMode = False
    startPos = None
    endPos = None

if not columnSelectMode:
    startPos = editor.getCurrentPos()
    endPos = startPos
    notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, "In Rectangle/Column Selection Mode")

else:
    endPos = editor.getCurrentPos()
    editor.setSel(startPos, endPos)
    editor.setSelectionMode( SELECTIONMODE.RECTANGLE )

    # this overrides the statusbar.. but the refresh UI will overwrite that with default
    notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, "")

    # use the upcoming activateFile to refresh UI
    #   otherwise, it doesn't _look_ like column/rectangle select)
    notepad.activateFile(notepad.getCurrentFilename())

columnSelectMode = not columnSelectMode

#console.show()
#console.write("toggle selection mode to {}: {} .. {}\n".format(columnSelectMode, startPos, endPos))
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/76441</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76441</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Wed, 27 Apr 2022 15:53:46 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 17:10:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> said in <a href="/post/76321">PythonScript Toggleable Script?</a>:</p>
<blockquote>
<p dir="auto">check if Notepad++ is closed</p>
</blockquote>
<p dir="auto">You scan do this with <code>NOTIFICATION.SHUTDOWN</code> in a <code>notepad.callback</code>.  To see how this works if you don’t know, type notepad.callback into the editor and then invoke PythonScript’s context-sensitive help on it.</p>
<p dir="auto">There’s also <code>SCINTILLANOTIFICATION.FOCUSOUT</code> which you could experiment with to see if it meets your needs.  That one is an <code>editor.callback</code>.</p>
<blockquote>
<p dir="auto">can return whether or not Notepad++ is the active window?</p>
</blockquote>
<p dir="auto">I suppose you could try things with the windows API function <a href="https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow" rel="nofollow ugc">GetForegroundWindow</a>.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76333</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76333</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 25 Apr 2022 17:10:41 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 15:00:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> Thanks for that! I still would like to know how to check if Notepad++ is closed or tabbed out of for future projects. Is there a function from Notepad, Editor or somewhere that can return whether or not Notepad++ is the active window? I would like to remedy this issue in my Script for satisfaction’s sake.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76321</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76321</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Mon, 25 Apr 2022 15:00:32 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 14:29:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> said in <a href="/post/76308">PythonScript Toggleable Script?</a>:</p>
<blockquote>
<p dir="auto">Do you have any ideas of an alternate way to achieve this?</p>
</blockquote>
<p dir="auto">Yes, here’s a demo script I call <code>RectangularSelectModeToggle.py</code>.  Each time it is run (hint: you can tie the running of it to a toolbar button) it toggles the shift+arrows selection functionality between selecting normal (what’s called a stream selection) and a selecting a column block (called rectangular selection).  The “Alt” key is not involved.  The script is fairly “low level”, and not a short one.</p>
<pre><code># -*- coding: utf-8 -*-
from __future__ import print_function

from Npp import *
import inspect
import os
import ctypes
from ctypes import wintypes
import platform

#-------------------------------------------------------------------------------

user32 = ctypes.WinDLL('user32')

notepad.hwnd = user32.FindWindowW(u'Notepad++', None)
editor1.hwnd = user32.FindWindowExW(notepad.hwnd, None, u'Scintilla', None)
editor2.hwnd = user32.FindWindowExW(notepad.hwnd, editor1.hwnd, u'Scintilla', None)

LRESULT = wintypes.LPARAM

WndProcType = ctypes.WINFUNCTYPE(
    LRESULT,  # return type
    wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM  # arguments
    )

running_32bit = platform.architecture()[0] == '32bit'

SetWindowLong = user32.SetWindowLongW if running_32bit else user32.SetWindowLongPtrW
SetWindowLong.restype = WndProcType
SetWindowLong.argtypes = [wintypes.HWND, wintypes.INT, WndProcType]

GWL_WNDPROC = -4

WM_KEYDOWN    = 0x100
WM_KEYUP      = 0x101
WM_SYSKEYDOWN = 0x104
WM_SYSKEYUP   = 0x105
WM_KILLFOCUS  = 0x8

VK_SHIFT         = 0x10
VK_CONTROL       = 0x11
VK_MENU = VK_ALT = 0x12

VK_LEFT  = 0x25
VK_UP    = 0x26
VK_RIGHT = 0x27
VK_DOWN  = 0x28

#-------------------------------------------------------------------------------

class RSMT(object):

    def __init__(self):

        self.debug = True if 1 else False

        self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0]

        self.shift_pressed = self.ctrl_pressed = self.alt_pressed = False

        self.altless_rectangular_select_mode_active = False
        # if this mode is active, user doesn't have to hold Alt while pressing Shift+arrows in order to make a rectangular selection

        self.new_editor1_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_editor1_wnd_proc_hook)
        self.orig_editor1_wnd_proc = SetWindowLong(editor1.hwnd, GWL_WNDPROC, self.new_editor1_wnd_proc_hook_for_SetWindowLong)

        self.new_editor2_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_editor2_wnd_proc_hook)
        self.orig_editor2_wnd_proc = SetWindowLong(editor2.hwnd, GWL_WNDPROC, self.new_editor2_wnd_proc_hook_for_SetWindowLong)

    def common_editor_wnd_proc_hook(self, hwnd, msg, wParam, lParam):

        retval = True  # default to allowing something other than this code to handle this message

        if msg in [WM_KEYDOWN, WM_SYSKEYDOWN]:

            if   wParam == VK_SHIFT:   self.shift_pressed = True
            elif wParam == VK_CONTROL: self.ctrl_pressed  = True
            elif wParam == VK_ALT:     self.alt_pressed   = True

            elif wParam in [ VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN ]:

                modifiers = ''
                modifiers += 'SHIFT+' if self.shift_pressed else ''
                modifiers += 'CTRL+'  if self.ctrl_pressed  else ''
                modifiers += 'ALT+'   if self.alt_pressed   else ''
                key = ''
                key += 'LEFT'  if wParam == VK_LEFT  else ''
                key += 'UP'    if wParam == VK_UP    else ''
                key += 'RIGHT' if wParam == VK_RIGHT else ''
                key += 'DOWN'  if wParam == VK_DOWN  else ''
                self.print(modifiers + key)

                if self.altless_rectangular_select_mode_active:

                    if self.shift_pressed and not self.ctrl_pressed and not self.alt_pressed:

                        retval = False  # allow no further processing of this message; it will be handled here

                        if wParam   == VK_LEFT:  editor.charLeftRectExtend()
                        elif wParam == VK_UP:    editor.lineUpRectExtend()
                        elif wParam == VK_RIGHT: editor.charRightRectExtend()
                        elif wParam == VK_DOWN:  editor.lineDownRectExtend()

        elif msg in [WM_KEYUP, WM_SYSKEYUP]:

            if wParam   == VK_SHIFT:   self.shift_pressed = False
            elif wParam == VK_CONTROL: self.ctrl_pressed  = False
            elif wParam == VK_ALT:     self.alt_pressed   = False

        elif msg == WM_KILLFOCUS:

            self.shift_pressed = self.ctrl_pressed = self.alt_pressed = False

        return retval

    def new_editor1_wnd_proc_hook(self, hwnd, msg, wParam, lParam):
        retval = self.common_editor_wnd_proc_hook(hwnd, msg, wParam, lParam)
        if retval: retval = self.orig_editor1_wnd_proc(hwnd, msg, wParam, lParam)
        return retval

    def new_editor2_wnd_proc_hook(self, hwnd, msg, wParam, lParam):
        retval = self.common_editor_wnd_proc_hook(hwnd, msg, wParam, lParam)
        if retval: retval = self.orig_editor2_wnd_proc(hwnd, msg, wParam, lParam)
        return retval

    def toggle(self):
        editor.setEmptySelection(editor.getCurrentPos())
        self.altless_rectangular_select_mode_active = not self.altless_rectangular_select_mode_active
        self.mb('Alt-less column select mode is now {}'.format('active' if self.altless_rectangular_select_mode_active else 'inactive'))

    def print(self, *args):
        if self.debug:
            #console.show()
            print('RSMT:', *args)

    def mb(self, msg, flags=0, title=''):  # a message-box function
        return notepad.messageBox(msg, title if title else self.this_script_name, flags)

#-------------------------------------------------------------------------------

if __name__ == '__main__':
    try:
        rsmt
    except NameError:
        rsmt = RSMT()
    rsmt.toggle()
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/76318</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76318</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 25 Apr 2022 14:29:35 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 14:04:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/3841">@peterjones</a> Thanks but I wanted to make it a toolbar icon attached to a PythonScript, I realize the same function can be achieved with Keyboard Shortcuts and Sticky Keys but having a toolbar icon is just my personal preference.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76314</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76314</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Mon, 25 Apr 2022 14:04:20 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 13:55:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/24980">@john-doe-1</a> ,</p>
<p dir="auto">If your goal is to have the “alt” key behave as “sticky”, Windows OS has an accessibility feature (“ease of access - keyboard”) for that.</p>
<p dir="auto"><a href="https://www.google.com/search?q=windows+10+sticky+alt+key" rel="nofollow ugc">https://www.google.com/search?q=windows+10+sticky+alt+key</a> =&gt;<br />
<a href="https://winaero.com/turn-on-or-off-sticky-keys-in-windows-10/" rel="nofollow ugc">https://winaero.com/turn-on-or-off-sticky-keys-in-windows-10/</a> or <a href="https://www.howtogeek.com/739764/how-to-turn-off-sticky-keys-on-windows-10/" rel="nofollow ugc">https://www.howtogeek.com/739764/how-to-turn-off-sticky-keys-on-windows-10/</a> or …</p>
<p dir="auto">No need to highjack the Alt key or any such thing.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76312</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76312</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 25 Apr 2022 13:55:23 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 13:26:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> <a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> Sorry input was being weird had to edit this reply. You make some good points, yes the holding of the “Alt” key does present some issues, most of them minor and not a problem for my uses. Except for inserting the “t” character and it being registed as “Alt” + “t” which would switch windows (depending on your configurations), that is a bit more of an issue. Do you have any ideas of an alternate way to achieve this? Thanks for your help so far!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76308</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76308</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Mon, 25 Apr 2022 13:26:59 GMT</pubDate></item><item><title><![CDATA[Reply to PythonScript Toggleable Script? on Mon, 25 Apr 2022 13:23:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://community.notepad-plus-plus.org/uid/7377">@alan-kilborn</a> Edit</p>
]]></description><link>https://community.notepad-plus-plus.org/post/76307</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/76307</guid><dc:creator><![CDATA[John Doe 1]]></dc:creator><pubDate>Mon, 25 Apr 2022 13:23:18 GMT</pubDate></item></channel></rss>