Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Customizing Windows 7 keyboard and mouse to act like Linux Code and Hacks

Posted by Admin • Thursday, April 13. 2017 • Category: Code and Hacks

After using only Linux for nearly 20 years, I'm being forced to use a Windows machine for work. To make matters worse, I'm really (really) used to Enlightenment shortcuts, yet I use XFCE (Xubuntu). So, I'd like to have a seamless experience if I can help it. This is a log of my experimentation.

Note that I am not talking about a skin - I don't care that much about the looks, and I don't need the Windows desktop to look like Mint or Unity. What I want is for Windows to respond with the same level of fluidity that I get from Linux


Step 1: Virtual Desktops

My VirtuaWin setup
My VirtuaWin setup

Solution: VirtuaWin

I never use Alt-TAB. I just have many virtuals and switch between them, every window is in the front. There are many solutions for this in Windows, starting with the venerable PowerToys Desktops (Sysinternals). The trouble with this very bare-bone Virtual Desktop solution is that it's very... bare-bone. So I'm using VirtuaWin instead, primarily because it has customizable HotKeys (including switch left/right/up/down).

So far my hotkey setup is partially junk - I don't plan to use the Alt-Win hotkeys (that's too hard), but I need to set them to something since I cannot directly assign the hotkeys I want. What I'd really like is to continue to use Alt-F keys to switch desktops. Unfortunately, Windows is kind of firm on the F keys... more on this later.

Step 2: Window Manipulation HotKeys

Solution: AutoHotKeys

Here are the keys I'm used to:
  • Close: Ctrl-Alt-x
  • Kill: Ctrl-Alt-k
  • Terminal: Ctrl-Alt-Insert
  • Run : Alt-ESC
  • Switch to Virtual Desktop #: Alt-F#
  • Switch to neighboring Virtual Desktop: Alt-Shift+Arrow Keys
So, you may see some issues here. Windows isn't very flexible on some of these keys. My first instinct was to use a hotkey application to generate an "Alt-F4" when I hit "Ctrl-Alt-x". That works, but I still want to remap Alt-F4 to desktop switching, so that isn't a good approach. Fortunately, AutoHotKeys can help here.

AutoHotKeys is interesting and probably aimed at developers, since it requires you to write scripts. That's OK, I'm a developer. So, let's begin:

Remapping Ctrl-Alt-x to the Window Close command is pretty simple (!^x means Alt-Ctrl-x):
!^x::WinClose, A
Of course, Alt-F4 will still close windows as well, but I'm taking care of that next.

As I mentioned earlier, I want to create these mappings for VirtuaWin (since it cannot directly listen on Alt-F*):
  • Alt-F1 -> Alt-Win-F1
  • Alt-F2 -> Alt-Win-F2
  • Alt-F3 -> Alt-Win-F3
  • Alt-F4 -> Alt-Win-F4
This is also quite simple:
!F1::Send, {alt down}{lwin down}{f1}{lwin up}{alt up}
!F2::Send, {alt down}{lwin down}{f2}{lwin up}{alt up}
!F3::Send, {alt down}{lwin down}{f3}{lwin up}{alt up}
!F4::Send, {alt down}{lwin down}{f4}{lwin up}{alt up}
I am merely triggering a keystroke on another keystroke, hoping that VirtuaWin is listening. I could have probably made my VirtuaWin keys more obscure, eg: Ctrl-Alt-Win-Shift-F*, to reduce the chance of them being used by something else down the line.

So now I have my HotKeys working. This only leaves the keys for run and terminal, but that's pretty simple.

The end result (my .ahk file):

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
!^x::WinClose, A 
!^k::WinKill, A
!Esc::Send, {lwin down}r{lwin up}
!^Ins::Run, C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -
!F1::Send, {alt down}{lwin down}{f1}{lwin up}{alt up}
!F2::Send, {alt down}{lwin down}{f2}{lwin up}{alt up}
!F3::Send, {alt down}{lwin down}{f3}{lwin up}{alt up}
!F4::Send, {alt down}{lwin down}{f4}{lwin up}{alt up}
I just save it to Documents (or wherever), then make a link into the Start Menu's "Startup" folder, and I'm all set. Note that AutoHotKey is very powerful, and in this example I'm only using a tiny fraction of what it can do, but I simply don't need to script anything fancy at the moment.

Step 3: Alt-Drag Window Moving and Resizing

Alt-Drag In Action

Solution: AltDrag

Naturally most Linux window manager users will be used to moving windows around by alt-clicking anywhere in them, and alt-right-clicking to resize them. Fortunately, AltDrag does exactly that for Windows, straight out of the box.

Step4: Focus follows mouse

mouse focus
CygWin window has focus

Solution: X-Mouse Controls

Not everyone prefers mouse focus (windows gain focus whenever the mouse is above them), but I do!. Having mouse pointer focus allows (for example) for typing into a partially obscured window without raising it. There is also a registry hack to do this without any binaries, but I have not tried it. This open-source tool seems to work great and requires no installation.

Step 5: A normal Terminal Emulator

Solution: CygWin

Cygwin seems to work pretty well for that (and for many other things). Note that my shortcuts above include launching Cygwin.
By the way, here area some useful extra Cygwin features to install (this is a note for myself):
  • wget
  • curl
  • vim
  • gvim
  • bash-completion
  • tmux
  • openssh
  • autossh
conemu with tmux
ConEmu running tmux
One note: if you want a multi-tabbed terminal to work with tmux, things get complicated.
  1. ConEmu. The default CygWin task in ConEmu has the same issue as Console2/ConsoleZ and cannot run tmux. You can, however, create a task that would launch bash instead of its built-in cygwin launcher, and then tmux will work. Sadly, if you do that, none of the ConEmu shortcuts will work while you're on that tab (so you're stuck using the mouse for moving between tabs, closing, opening new ones, etc. The proper solution is to install the msys connector as described here. Once you do that, you can set up the new executable as the default task and CygWin+tmux will fully work.
  2. ConsoleZ (a fork of Console/Console2). It can run bash (cygwin) as its shell in a tab, but if you do that, tmux will not start in it.


Step 6: A better Application Launcher

Launchy
Launchy

Solution: Launchy

Notice that in the AutoHotKeys file above I have my launcher hotkey redirect to Win+R, which is the Windows built-in run dialog. This is pretty limited in functionality, so a better launcher may be a third-party application like Launchy (which can handle its own hotkey assignments)

Some other options include:
  • SlickRun which is very neat but it seemed to want to help you with browser quick-search more than with launching applications
  • Enso, which may be great but it pulls in an entire Python interpreter, plus my hyperactive virus scanner told me that it's a Trojan

Step 7: A better File Manager

Double Commander
Double Commander

Solution: Total Commander or Double Commander

Yes, I realize that these are completely unlike any file manager integrated into the major distributions (except good old mc, which is command-line), but seriously, a dual-pane shortcut-centric file manager? What could be better?

Developer-Specific Stuff



These are primarily notes for me should I have to recreate my Windows setup.

GIT

  • Command-line GIT
  • Setting EDITOR or core.editor to vim doesn't seem to work for me, at least not in tmux (vim doesn't think that it's running in an interactive terminal). At least I can use a minimal Notepad++ (more details):
    git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Subversion

0 Trackbacks

  1. No Trackbacks

0 Comments

Display comments as (Linear | Threaded)
  1. No comments

Add Comment


You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

What is the primary language of this blog? (Anti-SPAM question)


Submitted comments will be subject to moderation before being displayed.