Jump to content

Resizing putty windows


Guest djsmith
 Share

Recommended Posts

Guest djsmith

I'm trying to resize a Putty Window using the WinMove() function, but the window refuses to resize. Here is my code:

$title = "MyProfile"
$cmd = "putty.exe -load MyProfile"

Run( $cmd )
; Need to sleep to allow putty to connect and load the title
sleep( 500 )
WinWaitActive( $title );
WinMove( $title, "", 0, 0, 500, 1000 )

The window is succesfully created and moved to coordinates (0,0), but not resized. Can anyone shed any light?

Note also that I've got SSH keys setup so I don't have to type a password, and putty automagically connects and authenticates.

I assume that the cause may be that putty only likes to resize in increments (presumably of 16 pixels) so that terminal lines aren't cut off when users resize the window.

Thanks in advance!

--Dave

Link to comment
Share on other sites

  • Developers

I'm trying to resize a Putty Window using the WinMove() function, but the window refuses to resize. Here is my code:

$title = "MyProfile"
$cmd = "putty.exe -load MyProfile"

Run( $cmd )
; Need to sleep to allow putty to connect and load the title
sleep( 500 )
WinWaitActive( $title );
WinMove( $title, "", 0, 0, 500, 1000 )

The window is succesfully created and moved to coordinates (0,0), but not resized. Can anyone shed any light?

Note also that I've got SSH keys setup so I don't have to type a password, and putty automagically connects and authenticates.

I assume that the cause may be that putty only likes to resize in increments (presumably of 16 pixels) so that terminal lines aren't cut off when users resize the window.

Thanks in advance!

--Dave

<{POST_SNAPBACK}>

Maybe the application doesn't allow you to resize it ??

Can you resize it manually ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yes. I can resize it manually.

--Dave

<{POST_SNAPBACK}>

The solution may lie in a previous message.....although I'll laugh if it's this simple.

WinMove( $title, "", 0, 0, 500, 1000 )

<snip>

I assume that the cause may be that putty only likes to resize in increments (presumably of 16 pixels) so that terminal lines aren't cut off when users resize the window.

Try resizing it to the increment specified...IE

WinMove($title,"",0,0,512,1024)

as both 512 and 1024 are evenly divisible by 16.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

  • Developers

:lmao: i duno why but can't get the WinMove to resize PuTTY either.

The WinSetState('PuTTY', "",@SW_MAXIMIZE) does work.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I don't think there's anything AutoIt can do about this.

Putty has its own non-standard and fairly complex window-resizing method. By default Putty changes the number of rows/columns when you resize the window.

If you change your Putty configuration to make it scale the screen font to match the window size, you'll find that AutoIt can resize the window successfully.

As a workaround, you can send mouse events to resize the window.

Link to comment
Share on other sites

Guest djsmith

I found a workaround that solves my problem. I modified the putty session's "rows" and "columns" fields under the session's "Window" settings. This lets putty do the resizing, and I don't bother with WinMove(). Works great now!

Link to comment
Share on other sites

  • 3 months later...

I'm trying to resize a Putty Window using the WinMove() function, but the window refuses to resize. Here is my code:

$title = "MyProfile"
$cmd = "putty.exe -load MyProfile"

Run( $cmd )
; Need to sleep to allow putty to connect and load the title
sleep( 500 )
WinWaitActive( $title );
WinMove( $title, "", 0, 0, 500, 1000 )

The window is succesfully created and moved to coordinates (0,0), but not resized. Can anyone shed any light?

Note also that I've got SSH keys setup so I don't have to type a password, and putty automagically connects and authenticates.

I assume that the cause may be that putty only likes to resize in increments (presumably of 16 pixels) so that terminal lines aren't cut off when users resize the window.

Thanks in advance!

--Dave

<{POST_SNAPBACK}>

Dave,

I don't use all the function in putty so I use plink.exe, comes with putty, and just use the cmd window to work from. If all you need is the telnet input this works better. You can pass it the putty session so that it uses your keys to connect.

Link to comment
Share on other sites

  • 3 years later...

I'm trying to resize a Putty Window using the WinMove() function, but the window refuses to resize. Here is my code:

$title = "MyProfile"
$cmd = "putty.exe -load MyProfile"

Run( $cmd )
; Need to sleep to allow putty to connect and load the title
sleep( 500 )
WinWaitActive( $title );
WinMove( $title, "", 0, 0, 500, 1000 )

The window is succesfully created and moved to coordinates (0,0), but not resized. Can anyone shed any light?

Note also that I've got SSH keys setup so I don't have to type a password, and putty automagically connects and authenticates.

I assume that the cause may be that putty only likes to resize in increments (presumably of 16 pixels) so that terminal lines aren't cut off when users resize the window.

Thanks in advance!

--Dave

Hi,

well my idea is the following (i already implemented it and it's working :) ) :

so i just guess I'll adjust the number of rows and columns in the registry before i open putty window.

like:

Global $ActualColumns   = Int(($PaneWidth-40)/8)        ; 40 - just a dummy constant
Global $ActualRows      = Int(($PaneHeight-20)/17)      ; 20 - statusbar height

; For example in CreateGUI function.

RegWrite("HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\TestSession\", "TermWidth", "REG_DWORD", $ActualColumns)
RegWrite("HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\TestSession\", "TermHeight", "REG_DWORD", $ActualRows)

Please notice you don't need to convert int to hex..

yes I know it takes time to guess the scale rate, but it worth it :)

dworldI'm new in autoit, but I like it. My mind is open to the new things.

Link to comment
Share on other sites

  • 1 month later...

I'm trying to resize a Putty Window using the WinMove() function, but the window refuses to resize. Here is my code:

$title = "MyProfile"
$cmd = "putty.exe -load MyProfile"

Run( $cmd )
; Need to sleep to allow putty to connect and load the title
sleep( 500 )
WinWaitActive( $title );
WinMove( $title, "", 0, 0, 500, 1000 )
#include <WinAPI.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

Func DoThing($handle,$nx,$ny,$nw,$nh)
    $pos = WinGetPos($handle)
    $x = $pos[0]
    $y = $pos[1]
    $w = $pos[2]
    $h = $pos[3]
    $WM_ENTERSIZEMOVE = 0x0231
    $WM_EXITSIZEMOVE = 0x0232
    if $nx <> $x or $ny <> $y Then
        WinMove($handle,"",$nx,$ny)
    EndIf
    if $nw <> $w Then
        $lpRect = DllStructCreate("int;int;int;int") ; LEFT, TOP, RIGHT, BOTTOM
        $WMSZ_BOTTOMRIGHT = 8
        DllStructSetData($lpRect,1,$nx)
        DllStructSetData($lpRect,2,$ny)
        DllStructSetData($lpRect,3,$nx + $nw)
        DllStructSetData($lpRect,4,$ny + $nh)
        _SendMessage($handle,$WM_ENTERSIZEMOVE)
        _SendMessage($handle,$WM_SIZING,$WMSZ_BOTTOMRIGHT,DllStructGetPtr($lpRect))
        $nw = DllStructGetData($lpRect,3) - DllStructGetData($lpRect,1)
        $nh = DllStructGetData($lpRect,4) - DllStructGetData($lpRect,2)
        _WinAPI_SetWindowPos($handle,0,0,0,$nw,$nh,$SWP_NOMOVE)
        _SendMessage($handle,$WM_EXITSIZEMOVE)
    EndIf
EndFunc

It's complicated, if putty receives a "WM_SIZE" message when it hasn't received a "WM_ENTERSIZEMOVE" message it will (as you've found out) return to it's original size.

To maintain the size stepped to rows and columns of the terminal, you have to give it a chance to do so

  • Send a WM_ENTERSIZEMOVE
  • Create a structure lpRect, fill it, send it with a WM_SIZING
  • read the returned values from the structure
  • resize according to those
  • then finally send a WM_EXITSIZEMOVE.

Hope this helps.

Link to comment
Share on other sites

  • 2 years later...

Hi,

[...]
Global $ActualColumns   = Int(($PaneWidth-40)/8)        ; 40 - just a dummy constant
Global $ActualRows      = Int(($PaneHeight-20)/17)      ; 20 - statusbar height

If we need to use size values from "AutoIt Window Info" this code is better:

Global $ActualColumns   = Int(($PaneWidth-26)/8)
Global $ActualRows      = Int(($PaneHeight-29)/15)

Code is NOT perfect because "window info" shows intermediate values

ex:

putty width 100 = PaneWidth should be 826

putty width 101 = PaneWidth should be 834 (826 + 8)

sometimes "Window Info" shows value between 827 and 833 (this is not good because results are not precise)

Best to use values directly from putty:

Posted Image

; session1 - window 1
$PuttyWidth = '126'
$PuttyHeight = '22'
$PaneWidth  = Int(($PuttyWidth*8)+26)
$PaneHeight = Int(($PuttyHeight*15)+29)
Global $ActualColumns   = Int(($PaneWidth-26)/8)
Global $ActualRows    = Int(($PaneHeight-29)/15)

RegWrite("HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\session1\", "TermWidth", "REG_DWORD", $ActualColumns)
RegWrite("HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\session1\", "TermHeight", "REG_DWORD", $ActualRows)

Run(&$putty' -load "session1"')
WinWait("session1", "")
WinMove("session1", "", 0, 504)

; session1 - window 2
[...]
; session1 - window 3
[...]

Posted Image

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