Turn Backspace off (and on) in your Windows machine with AutoHotKey

Aug 17, 2014 14:57

Why turn Backspace off?

Some writing exercises (freewriting is one example) and challenges (such as NaNoWriMo) aim at freeing the mind to produce whatever comes up, and discourage editing at the writing stage. For many of us, however, deleting typos or awkward turns of phrase is a reflex that simple willpower cannot turn off. For this reason the web app ilys (which is crowdfunding via Kickstarter) has proved useful for people who want to turn off their inner editor while writing. Since ilys obscures the text that is being written, others turn to apps like Final Deadline or Momentum Writer.

Those who don't trust their content to an app whose stability they're not sure of, or have another application whose interface they like better, may have wished that the writing software of their choice supported disabling backspace and delete. If you're on Windows and install AutoHotKey, you can get that wish with a few lines of code.

What's AutoHotKey?

Jesus in binary form, baby. AHK is a script interpretation engine for Windows that runs in the background and lets you remap your keyboard, specify customized shortcuts, and more. I plan to write in more depth about the things I do with it, but for the purpose of this post it's enough to know that it lets you turn backspace and other keys on and off with a keyboard combination.

Enough preliminaries, give me the script already!

Sure thing! Follow the steps below:

First, if you haven't already, download and install AutoHotKey. You can find the latest download file on their hompage. You'll probably want to add it to your startup programs so it runs in the background whenever you boot up.

Second, open your AutoHotKey script file. You probably specified a path for this during setup, but the easiest way is to go to your toolbar, right-click the green AutoHotKey icon, and choose "Edit this script."



Yes, I have far too much crap on my toolbar.

Third, copy-and-paste the following script into somplace in your script file. I call it, appropriately enough, BS Off.

;BS Off script: Toggles Backspace and such other keys as you choose to include in the toggle.
;Script originally provided here with directions: http://ljlee.dreamwidth.org/53114.html

;This sets up the tooltip timeout. You'll thank me later.

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

;This is the toggle combo that turns your backspace (and other keys, if you want) on or off.
;The key combination is SHIFT+BACKSPACE. For info on changing that, see below on the page.
;On pressing the key combo, a tooltip will tell you whether backspace is on or off.

$+Backspace::
If !(BsOff = 1)
{
BsOff = 1
ToolTip, Backspace turned off
SetTimer, RemoveToolTip, 3000
}
Else
{
BsOff = 0
ToolTip, Backspace is turned back on
SetTimer, RemoveToolTip, 3000
}
Return

;The below controls Backspace key behavior.

$Backspace::
If !(BsOff = 1)
{
Send, {Backspace}
}
Else
{
Return
}
Return

;This part does the same with the Delete key.

$Delete::
If !(BsOff = 1)
{
Send, {Delete}
}
Else
{
Return
}
Return

;The below turns the direction keys off whet Backspace is off.
;If you want your direction keys to work is BS Off mode, omit the below.

$Up::
If !(BsOff = 1)
{
Send, {Up}
}
Else
{
Return
}
Return

$Down::
If !(BsOff = 1)
{
Send, {Down}
}
Else
{
Return
}
Return

$Left::
If !(BsOff = 1)
{
Send, {Left}
}
Else
{
Return
}
Return

$Right::
If !(BsOff = 1)
{
Send, {Right}
}
Else
{
Return
}
Return

Fourth, right-click on the AutoHotKey icon and choose "reload script."

Fifth, press Shift+Backspace to turn BS on and off. Try backspace, delete, and any other keys you chose to axe in BS Off mode. In my tests the script worked in every Windows application I tried.

I want a different toggle key combination!

Way ahead of ya. Here are other possible triggers that you can use to replace the "$+Backspace" (Shift+Backspace) portion of the script:

Ctrl+Backspace:

$^Backspace

Alt+Backspace:

$!Backspace

Windows+Backspace:

$#Backspace

(Also, "BS" is an actually legit shorthand for Backspace so use that if you want to get into the spirit.)

It shouldn't be hard to figure out that + is "shift," ^ is "ctrl," ! is "alt," and # is "Windows" in AHK-land. The dollar sign suppresses the key or combo's default behavior, for instance Backspace's default function or the word-delete function of Ctrl+Backspace.

If you want other trigger keys or want to see how you can expand the script, check out the hotkey documentation and try the community forums.

Limitations

I am not a programmer and far from an expert AHK coder, so this solution is probably way clunkier than it needs to be. This is just a quick-and-dirty thing that gets the job done. It also doesn't catch modifier keys, so you can still do things like Ctrl + Backspace (erase backward by word) and Shift + direction key and then overwrite. At my level of knowledge trying to catch all that would just make the script longer and messier, plus it's only designed to catch reflexive backspace presses and navigation attempts. If you're desperate enough to try other key combos to edit, then you'll long since have turned Backspace back on.

So there's your BS Off script. Go to town with it! Dreamwidth entry URL: http://ljlee.dreamwidth.org/53114.html

writing, resource, tech

Previous post Next post
Up