Jump to content

Sending Esc+a to non-active PuTTY


Hcc
 Share

Go to solution Solved by MikahS,

Recommended Posts

Hi!

I'm completely new with AutoIt, and I confess I don't have the time to learn scripting with it right now.

I am looking for a way to send a Esc+a keypress to a PuTTY window with a predefined key even when PuTTY is inactive, so that I can easily switch between Irssi (Irc client running on Screen on PuTTY) channel windows.

I am using a dual monitor setup on my system, and for example, when I'm using Firefox on my main screen and PuTTY on my secondary screen, I want to be able to switch Irssi windows with a single keypress (a function key (F1-F12) possibly) when Firefox or any other program is active. Is this possible with AutoIt, and would anyone of you more eperienced guys be willing to write me a script for this purpose?

Thank you in advance for all help!

-Hcc, Finland

 

Edited a missing parenthesis messing up a sentence

Edited by Hcc
Link to comment
Share on other sites

  • Solution

Hm, something like this might help give you a better understanding of what's going on:

#include <WindowsConstants.au3>


HotKeySet("{F1}", "sendKey")  ; set the F1 key to run the sendKey() function
HotKeySet("{F2}", "Quit")  ; set the F2 key to stop the script from running


While 1
    ;keep this script running infinitely
WEnd


Func sendKey()
    Local $hWin, $pWin, $pWinError
    $pWin = WinGetHandle("") ; get handle to the window that is being used before making Putty the active window
    $hWin = WinActivate("PuTTY") ; make Putty the active window
    If $hWin = 0 Then  ; if we couldn't make Putty the active window, then..
        MsgBox(0, "title", "Could not make Putty the active window")  ; tell us!
        Return ; quit the function since we couldn't make Putty the active window
    EndIf
    Send("{ESC}a") ; if Putty is the active window, then send ESCAPE + "a"
    $pWinError = WinActivate($pWin) ; active the previously active window, since we are done sending to Putty
    If $pWinError = 0 Then ; if we can't find any previously opened window, then..
        MsgBox(0, "prev", "Could not find previously used window") ; tell us!
    EndIf
EndFunc

Func Quit()
    MsgBox(0, "Quit", "Stopping script") ; tell us we are stopping the script..
    Exit ; stop the entire script
EndFunc
 
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

You're very welcome, and no need your gratitude is enough for me :thumbsup:

EDIT: grammar

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Hi again, I'm returning with a question related to the script provided by MikahS.

I've added some functions to it, and now I'm facing a problem - how can I simulate pressing the left arrow twice and then the up arrow once, all this while holding the WIN key down? I tried something like this:


Send("{LWIN down}{LEFT 2}{UP}{LWIN up}")

but it wasn't any good. Help, please? :)

Edited by Hcc
Link to comment
Share on other sites

This should do it :)

Send("{LWINDOWN}")
Send("{LEFT 2}")
Send("{UP}")
Send("{LWINUP}")

EDIT: Fixed fourth line send statement - from "Send{" to "Send("

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Glad to help @Hcc :) nice catch ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...