• Support
  • Articles
  • Resources
  • Products

Function Buttons

Moderator: boris

6 postsPage 1 of 1

IshmaelCallMe
Guru

Posts:
672
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Mon Apr 14, 2008 10:05 pm
I improved this AutoIt script to add function buttons to TeraTerm. Original tread with history is here:

viewtopic.php?t=734

Code: Select all

  1.  
  2. #NoTrayIcon
  3. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  4. #AutoIt3Wrapper_icon=rose.ico
  5. #AutoIt3Wrapper_outfile=TERATERM_ToolBar.exe
  6. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  7. #include <GUIConstants.au3>
  8. #include <Array.au3>
  9. Dim $Buttons[5][2] = [[3, ''], _    ;the 3 here is the number of buttons, the 5 being two greater than this
  10.         ['Macro 1', 'C:\Program Files\TTERMPRO\ExistingMacroRun\try.ttl'], _
  11.         ['Macro 2 with a very long label', 'C:\Program Files\TTERMPRO\ExistingMacroRun\try2.ttl'], _
  12.         ['This is Macro 3 with a very long label', 'C:\Program Files\TTERMPRO\ExistingMacroRun\try3.ttl'], _
  13.         ['', '']] ;not needed if only the ini file is used
  14. $IniFileName = 'TERATERM_ToolBar.ini'
  15. If $CmdLine[0] Then $IniFileName = $CmdLine[1] ;ini file name is first command line parameter, if it exists
  16. $ButtonHeight = IniRead($IniFileName, 'Sizes', 'ButtonHeight', 50) ;get setup from ini file, if it exists
  17. $ButtonWidth = IniRead($IniFileName, 'Sizes', 'ButtonWidth', 100)
  18. $var = IniReadSection($IniFileName, "Definitions")
  19. If Not @error Then $Buttons = $var
  20.  
  21. Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
  22. $loc = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\UTF-8 TeraTerm Pro with TTSSH2_is1', 'InstallLocation')
  23. $exe = '"' & $loc & 'ttermpro.exe" '; & '/F ' & $loc & 'TERATERM.INI'
  24. For $i = 2 To $CmdLine[0]
  25.     $exe &= $CmdLine[$i] & ' '
  26. Next
  27. $pid = Run(@ComSpec & " /c " & $exe, $loc, @SW_HIDE) ;Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)
  28. While 1 ;find window handle of TERATERM instance that was just started
  29.     $wlist = WinList('[CLASS:VTWin32]')
  30.     For $i = 1 To $wlist[0][0]
  31.         If _getppid(WinGetProcess($wlist[$i][1])) == $pid Then
  32.             $hwin = $wlist[$i][1] ;found Tera Term window handle
  33.             ExitLoop 2
  34.         EndIf
  35.     Next
  36. WEnd
  37.  
  38. Dim $ibutton[$Buttons[0][0] + 1] ;create GUI
  39. $pos = WinGetPos($hwin)
  40. $Form1 = GUICreate('', $pos[2] - 2, $pos[3] + $ButtonHeight + 5, Default, Default, BitOR($WS_SYSMENU, $WS_CLIPCHILDREN, $WS_SIZEBOX, $WS_MINIMIZEBOX))
  41. For $i = 1 To $Buttons[0][0] ;create tool bar buttons
  42.     $ibutton[$i] = GUICtrlCreateButton($Buttons[$i][0], (($i - 1) * ($ButtonWidth + 5)), $pos[3] - 24 + 5, $ButtonWidth, $ButtonHeight, $BS_MULTILINE)
  43. Next
  44. WinMove($hwin, '', -5, -24) ;move it so the title bar doesnt show
  45. DllCall("user32.dll", "int", "SetParent", "hwnd", $hwin, "hwnd", $Form1) ;the MAGIC - set TeraTERM window as a child of our GUI window
  46. GUISetState(@SW_SHOW)
  47. $pos = WinGetPos($hwin)
  48. WinMove($Form1, '', Default, Default, $pos[2] - 2) ;resize GUI to fit TeraTERM
  49.  
  50. Opt("WinWaitDelay", 100) ;250 milliseconds
  51. Opt("SendKeyDelay", 5) ;5 milliseconds
  52. $title = ''
  53. While 1
  54.     If Not ProcessExists($pid) Then Exit ;If TeraTERM goes away, we do too
  55.     $otitle = $title
  56.     $title = WinGetTitle($hwin) ;if title changed, update toolbar title
  57.     If $otitle <> $title Then WinSetTitle($Form1, '', 'Macro Tool Bar by BPR for TeraTERM window  "' & $title & '"')
  58.     $nMsg = GUIGetMsg()
  59.     If $nMsg == $GUI_EVENT_CLOSE Then Exit ;hit x box and close
  60.     If $nMsg == $GUI_EVENT_RESIZED Then ;resize TeraTERM window if our GUI is resized
  61.         $guipos = WinGetPos($Form1)
  62.         WinMove($hwin, '', -5, -24, $guipos[2] + 10, $guipos[3] - $ButtonHeight - 5) ;size TeraTERM to new GUI size
  63.         $pos = WinGetPos($hwin)
  64.         WinMove($Form1, '', Default, Default, $pos[2] - 2) ;resize GUI width to fit TeraTERM since it quantises its size
  65.     EndIf
  66.     For $i = 1 To $Buttons[0][0]
  67.         If $nMsg == $ibutton[$i] Then
  68.             WinActivate($hwin)
  69.             WinWaitActive($hwin)
  70.             Send('!om') ;bring up open macro box
  71.             If (WinWait('MACRO: Open macro', '', 2)) Then
  72.                 ControlSetText('MACRO: Open macro', '', 'Edit1', $Buttons[$i][1])
  73.                 ControlClick('MACRO: Open macro', '', 'Button2')
  74.             Else
  75.                 MsgBox(0, 'ERROR', 'Unable to open Macro "' & $Buttons[$i][1] & '" on window with title "' & $title & '"')
  76.             EndIf
  77.         EndIf
  78.     Next
  79.     Sleep(10)
  80. WEnd
  81.  
  82. Func _getppid($p)
  83.     $wbemFlagReturnImmediately = 0x10
  84.     $wbemFlagForwardOnly = 0x20
  85.     $strComputer = "."
  86.     $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
  87.     $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
  88.     For $objItem In $colItems
  89.         If $objItem.ProcessId == $p Then Return ($objItem.ParentProcessId)
  90.     Next
  91. EndFunc   ;==>_getppid
  92.  


This uses ini files of the form:

Code: Select all

  1.  
  2. [Sizes]
  3.     ButtonWidth=200
  4.     ButtonHeight=60
  5. [Definitions]
  6.     Macro 1=C:\Program Files\TTERMPRO\ExistingMacroRun\try.ttl
  7.     This is Macro 2 with a very long label=C:\Program Files\TTERMPRO\ExistingMacroRun\try2.ttl
  8.     This is Macro 3 with a very long label=C:\Program Files\TTERMPRO\ExistingMacroRun\try2.ttl
  9.     Autoit Command=!msgbox(0,'try','try')
  10.  
gusaniljo
Newbie

Posts:
1
Joined: Mon Nov 14, 2011 2:33 pm
by gusaniljo » Mon Nov 14, 2011 2:35 pm
thanks for sharing the info)) finally have found what was looking for :D
dpena
Coach

Posts:
144
Joined: Thu Jul 09, 2009 6:14 pm
by dpena » Thu Dec 22, 2011 7:50 am
Hi IshmaelCallMe,

I loaded Autoit and decided to explore it using your coding efforts. Unfortunalty I am new to Autoit and do not understand how to make your code work.

Would it be to much trouble to ask for a step by step outline to invoke your Autoit script??

I have copied your Autoit script and saved it as a 'test.au3' in my "My Documents" directory.

I have also created a "TERATERM_ToolBar.ini" in my "C:\Program Files\teraterm" directory with the contents of the following in the file:

Code: Select all

  1.  
  2. [Sizes]
  3.     ButtonWidth=200
  4.     ButtonHeight=60
  5. [Definitions]
  6.     Macro 1=C:\Program Files\TTERMPRO\ExistingMacroRun\try.ttl
  7.     This is Macro 2 with a very long label=C:\Program Files\TTERMPRO\ExistingMacroRun\try2.ttl
  8.     This is Macro 3 with a very long label=C:\Program Files\TTERMPRO\ExistingMacroRun\try2.ttl
  9.     Autoit Command=!msgbox(0,'try','try')
  10.  


I have Autoit installed but do not understand how to make all this work with Tera Term.

Thanks,
IshmaelCallMe
Guru

Posts:
672
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Wed Jan 11, 2012 4:06 pm
Been a couple years since I played with this, but all you should have to do is execute the autoit script and it will bring up TeraTERM and attach to it. You can make a shortcut to execute the autoit script by starting autoit3.exe with the script path and name as the first command line parameter.
gvinet55
Newbie

Posts:
1
Joined: Mon Apr 16, 2012 9:55 am
by gvinet55 » Mon Apr 16, 2012 9:57 am
Thanks for letting me know about other good stuff!
IshmaelCallMe
Guru

Posts:
672
Joined: Thu Jan 26, 2006 2:28 am
by IshmaelCallMe » Wed Feb 20, 2013 3:16 pm
Look here viewtopic.php?f=13&t=2236 for improved version.
Display posts from previous:
Sort by:

6 postsPage 1 of 1

Users browsing this forum: No registered users
cron