4

I run terminal-mode Emacs (using the -nw option) inside Screen on my office Debian box. This way, I can log in my box with ssh from anywhere and work even with slow or intermittent connection.

When I log in from Windows using Putty, I miss the possibility of using the Alt-Tab key combination (M-TAB in Emacs parlance). I compensate using the two keys Esc and Tab, but that's two key presses, which is slower.

I just discovered that using Autohotkeys I can make Ctrl-Tab do the same as Alt-Tab with this rule:

LControl & Tab::AltTab

and I can disable Alt-Tab altogether with this other rule:

!Tab::Return

but this is not what I want. I need to copy the functionality of Alt-Tab on some other hot key (Ctrl-Tab is okay and the first rule does that) and additionally I want the Alt-Tab key to be passed to Putty when I am using it (which would pass it to Screen, which would pass it to Emacs). In other words, Alt-Tab should not be disabled, but its special meaning should be deleted.

Is this possible with Windows?

Syscall
  • 19,327
  • 10
  • 37
  • 52
  • 1
    I haven't used this kind of setup, but guessing from the description, you can probably just send Esc and Tab when putty window is active: `#ifwindowActive putty` \n `!Tab::send {Esc}{Tab}` – wOxxOm Jun 21 '17 at 11:47
  • Thank you for the idea, and yes, it works :) Only, the correct keyword is IfWinActive, and I have yet to figure out how to make it recognise the putty window, so I bound Al-Tab unconditionally. – Francesco Potortì Jun 21 '17 at 17:44
  • It is possible. I use Ctrl-Tab on both Linux and Windows to switch between applications, so I leave Alt-Tab free for Emacs. Unfortunately my Windows laptop has been segregated in my office for one month and still is, so I cannot report what I exactly wrote on Autohotkey conf file :( – Francesco Potortì Apr 24 '20 at 11:45

2 Answers2

1

While I don't fully understand the issue you're encountering, this framework should give you something to work with for conditional actions based on the window.

!Tab::
{
WinGetTitle, Title, A
if (RegExMatch(Title, "PuTTY.*"))
{
    ; Do something if PuTTY is the active window.
}else{
    ; Do something else if PuTTY is NOT the active window.
}}
David Metcalfe
  • 2,237
  • 1
  • 31
  • 44
0

Working with the answers I got from several hepful users, I got to the final solution I have used for some time now. Here is the Autohotkeys script that I put on my desktop and that I double-click every time I have to restart Windows:

File "alt-tab to ctrl-tab.ahk"

#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.

LControl & Tab::AltTab
; !Tab::Return
; #IfWinActive, putty
!Tab::send {Esc}{Tab}
  • Put the script in your [startup folder](https://helpdeskgeek.com/windows-10/how-to-access-the-windows-10-startup-folder/) if you don't want to rerun the script manually every time you restart. – Spyre Aug 12 '21 at 09:21
  • Thanks. However, I purposefully avoided to do that, because I want to enable that feature explicitly, and I want possible different users of the same laptop not to be taken by surprise – Francesco Potortì Aug 13 '21 at 12:36