I recently <a href="/2014/08/25/switching-end-and-insert-key-on-the-lenovo-yoga/">lamented about switching two keys on my new Lenovo Yoga</a>. Big problem: In my office, I attach that notebook to a docking station and to that docking station I attach a <a href="http://www.daskeyboard.com/" target="_blank">keyboard</a>. On that keyboard, all keys are precisely the way I want them to be. Therefore, I do <i>not</i> want to switch the <b>Insert</b> and <b>End</b> keys when I am docked. I ended up writing a little batch script based on <a href="https://code.google.com/p/killkeys/wiki/ScancodeMap" target="_blank">this nice google code wiki entry</a> for the registry update and <a href="http://stackoverflow.com/a/24665214/1578458" target="_blank">this stackexchange answer to elevate the batch script</a>: ```bash @ECHO OFF NET FILE 1>NUL 2>NUL if '%ERRORLEVEL%' == '0' goto run powershell "saps -filepath %0 -verb runas" >nul 2>&1 goto eof :run REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" ^ /v "Scancode Map" >nul 2>&1 IF '%ERRORLEVEL%' == '0' goto remove <nul set /p ="> adding scancode map " REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" ^ /v "Scancode Map" /t REG_BINARY /f ^ /d 00000000000000000300000052E04FE04FE052E000000000 >nul 2>&1 IF '%ERRORLEVEL%' == '0' goto success goto fail :remove <nul set /p ="> removing scancode map " REG DELETE "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" ^ /v "Scancode Map" /f >nul 2>&1 IF '%ERRORLEVEL%' == '0' goto success goto fail :fail echo failed. pause goto eof :success echo succeeded. pause ``` Sadly, it always requires a reboot for the changes to take effect.


Nikolai asked me how to open a Python interpreter prompt from the console with a certain module already imported. For the record, the <a href="http://docs.python.org/2/using/cmdline.html" target="_blank">Python command line switches</a> tell us that `python -i -m module` is the way to start the prompt and load `module.py`. That made me wonder whether I can stuff it all into one batch file, and I came up with the following `test.bat`: ```python REM = ''' @COPY %0.bat %0.py @python %0.py @DEL %0.py @goto :eof ::''' del REM for k in range(70): print(k) ``` That script will ignore the first line because it is a comment, then copy itself to `test.py`, then launch python with this argument. Afterwards, `test.py` is deleted and the script terminates without looking at any of the following lines. Note that `::` is yet another way to comment in Batch. Python, however, will see a script where the variable `REM` is defined as a multi-line string and deleted right after that. After this little stub, you can put any python code you want. Well. I thought it was funky.