Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Monday, August 03, 2009

AutoHotKey Swap Delete and Backspace

I found that the standard AutoHotkey technique to swap BS and Del



    Delete::Backspace
    Backspace::Delete



did not work for me, because I need to turn it on and off quite a lot as I move around.

So, I wrote the following.

Would post it to some AutoHotKey sharing site, but can't seem to access such at the moment.


;
; AutoHotkey Version: 1.0.48.3
; Language: English
; Platform: Win9x/NT/XP
; Author: Andy Glew: andy.glew@intel.com, ag-ahk@patten-glew.net
;
; Script Function:
; Swap Delete and Backspace
; with a menu to enable/disable.
;
; Why?: because I am constantly docking and undocking my laptop
; when undocked I don't need to swap Del and BS
; but when docked at work, with my Happy Hacker keyboard, I do.
;
; And I found that killing the script was a bit too annoying.

;-----------------------------------------------------------------------------

#InstallKeybdHook ; unconditionally installing the keyboard hook.
; TBD: may not be necessary
; TBD: may waste memory and slow down system

#SingleInstance force ; replace any already running instance of this script

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; Autoexec'ed
Menu,DeleteBackspace,Add,Swap backspace and delete,ToggleBsDelSwapSetting
Menu,DeleteBackspace,Add,#!Del/BS - this menu to enable/disable,ToggleBsDelSwapSetting
SwapBackspaceAndDelete = 0
Return

ToggleBsDelSwapSetting:
Menu,DeleteBackspace,ToggleCheck,Swap backspace and delete
SwapBackspaceAndDelete := SwapBackspaceAndDelete ^ 1
Return


;=============================================================================

; #-Win, !-Alt, ^-Ctl, +-shift
; # right Win, etc.
; * - ignore other modifiers
; $ - prevent self-recursion (e.g. {Del} can send {Del}

;=============================================================================

; On the Happy Hacker keyboard, I need to swap Delete and Backspace

; TBD: I wish that I could create a function to do such swapping, but I seem to be unable to in AutoHotKey

$Delete::
;MsgBox Delete %SwapBackspaceAndDelete%
if ( SwapBackspaceAndDelete ) {
SendPlay, {BackSpace}
}
else {
SendPlay, {Delete}
}
Return

$BackSpace::
;MsgBox BackSpace %SwapBackspaceAndDelete%
if ( SwapBackspaceAndDelete ) {
SendPlay, {Delete}
}
else {
SendPlay, {BackSpace}
}
Return

$NumpadDel::
;MsgBox NumPadDel %SwapBackspaceAndDelete%
if ( SwapBackspaceAndDelete ) {
SendPlay, {BackSpace}
}
else {
SendPlay, NumPadDel}
}
Return


#!Delete::
#!BackSpace::
#!NumpadDel::
Menu,DeleteBackspace,Show
Return