Sign in to follow this  
Followers 0
JohnBailey

TrayEvent outside the WhileLoop

12 posts in this topic

The tray menu items to invoke an action when clicked. I've tried using TraySetOnEvent for each item (no dice). Here's the script below. Can someone give me a nudge in the right direction (also if someone has a better idea for the tabbing part that would be much appreciated).

Global $version = '1.0.0'


#include <Constants.au3>
#include <GUIConstants.au3>
#Include <Misc.au3>
Opt("WinSearchChildren", 1)
Opt ("GUIOnEventMode", 1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

Global $dll = DllOpen("user32.dll")
;HotKeySet("{ESC}", "Terminate")

#Region ### START Koda GUI section ### Form=i:\sai\auto-it files\gui designs\autotab.kxf
$ParentWin = GUICreate("AutoTab    v"&$version, 336, 131, 193, 115)
$Input1 = GUICtrlCreateInput("1", 160, 22, 43, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Use  ", 121, 54, 97, 17, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_RIGHTBUTTON,$BS_RIGHT,$WS_TABSTOP))
$Label1 = GUICtrlCreateLabel("Tab Amount", 97, 25, 62, 17)
$Label2 = GUICtrlCreateLabel("Press Down Arrow to use when Use is checked", 48, 99, 250, 17, $SS_CENTER)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

$on = TrayCreateItem("AutoTab on", -1, -1, 1)
$off = TrayCreateItem("AutoTab off", -1, -1, 1)
TrayItemSetState(-1, $TRAY_CHECKED)
TrayCreateItem("")
$TrayExititem = TrayCreateItem("Exit")

TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"TrayEvents")
TraySetOnEvent($on,"TrayEvents")

TraySetState()
TraySetClick(16)

GUISetState(@SW_SHOW)

While 1
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
        TrayItemSetState($on, $TRAY_CHECKED)
        TrayItemSetState($off, $TRAY_UNCHECKED)
        If _IsPressed("28", $dll) Then
            AddTab()
        EndIf
    Else
        TrayItemSetState($on, $TRAY_UNCHECKED)
        TrayItemSetState($off, $TRAY_CHECKED)
    EndIf
    Sleep(40)
WEnd

Func AddTab()
    If GUICtrlRead($Input1) = 1 Then
        Send('{UP}{TAB}{DOWN}{HOME}')
    ElseIf GUICtrlRead($Input1) = 2 Then
        Send('{UP}{TAB}{TAB}{DOWN}{HOME}')
    ElseIf GUICtrlRead($Input1) = 3 Then
        Send('{UP}{TAB}{TAB}{TAB}{DOWN}{HOME}')
    ElseIf GUICtrlRead($Input1) = 3 Then
        Send('{UP}{TAB}{TAB}{TAB}{TAB}{DOWN}{HOME}')
    EndIf
EndFunc


    ;test
        ;test
;test

Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Terminate()
            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            WinSetState($ParentWin, "", @SW_HIDE)
            TrayTip(@ScriptName, "has been minimzed. Doubleclick here to restore", 10, 0)
            
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
            ;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
    EndSelect
    
EndFunc

Func TrayEvents()
    Select
       Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOUBLE
            WinSetState($ParentWin, "", @SW_SHOW)
            WinSetState($ParentWin, "", @SW_RESTORE)
            TrayTip(@ScriptName, "", 0)
    EndSelect
    Local $tsm = TrayGetMsg()
    Switch $tsm
        Case $on
            MsgBox(0,'yes',@TRAY_ID)
            GUICtrlSetState($Checkbox1,$GUI_CHECKED)
        Case $off
            GUICtrlSetState($Checkbox1,$GUI_UNCHECKED)
        Case $TrayExititem
            Terminate()
    EndSwitch
EndFunc

Func Terminate()
    DllClose($dll)
    Exit
EndFunc

A decision is a powerful thing

Share this post


Link to post
Share on other sites



The tray menu items to invoke an action when clicked. I've tried using TraySetOnEvent for each item (no dice). Here's the script below. Can someone give me a nudge in the right direction (also if someone has a better idea for the tabbing part that would be much appreciated).

I'm a dummy. :whistle: I was using the wrong Tray event

This is the one I needed

TrayItemSetOnEvent($on,"TrayEvents")


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Tray event mode doesn't apply to the menu items, I don't think.

As for the tabbing, this would be much more effective.

Func AddTab()
    Local $tabcount = Number(GUICtrlRead($Input1))
    Local $sendstring = '{UP}'
    Local $forvar
    For $forvar = 1 To $tabcount
        $sendstring &= '{TAB}'
    Next
    $sendstring &= '{DOWN}{HOME}'
    Send($sendstring)
EndFunc

Share this post


Link to post
Share on other sites

Tray event mode doesn't apply to the menu items, I don't think.

As for the tabbing, this would be much more effective.

Func AddTab()
    Local $tabcount = Number(GUICtrlRead($Input1))
    Local $sendstring = '{UP}'
    Local $forvar
    For $forvar = 1 To $tabcount
        $sendstring &= '{TAB}'
    Next
    $sendstring &= '{DOWN}{HOME}'
    Send($sendstring)
EndFuncoÝ÷ Ûú®¢×XD0Bbr«w}ÈßÙèØb²j+)àN­®$³}÷Üg¶§Í÷:v§¢Ø^®z-y:ÚÈ^'­:q/z{p¢¹,Â+a¶¢µé¬nëS­¬zÓ§÷§µÚ²z-Zäxz»"¢v®¶­sb672ÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÐ WF÷# ¦öâ&ÆW ÖöFfW#¢æÖP FFRÖöFfVC¢róRó#p 67&DgVæ7Föã F2VÇ2Æ÷BFòf÷&ÖB67&@ WFôBfW#¢fW'6öà  äõDS¢Fæ·2Fò&6&B&ö&W'G6öâf÷"FRFEF"6öFR&Wg6öà  67&BfW'6öã¢ãã&6R6öFRâ×&÷fVBöFFVBfVGW&W2â67&BW'&÷'26÷'&V7FVB  67&BWFFR7F÷'  ¢66RÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒÒФvÆö&Âb33c·fW'6öâÒb33³ããb33°  ¢6æ6ÇVFRfÇC´6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇC´uT6öç7FçG2æS2fwC°¢4æ6ÇVFRfÇC´Ö62æS2fwC°¤÷BgV÷Cµvå6V&66ÆG&VâgV÷C²Â¤÷BgV÷C´uTöäWfVçDÖöFRgV÷C²Â¤÷BgV÷CµG&öäWfVçDÖöFRgV÷C²Ã¤÷BgV÷CµG&ÖVçTÖöFRgV÷C²Ã²FVfVÇBG&ÖVçRFV×267&BW6VBôWBvÆÂæ÷B&R6÷vâà ¤vÆö&Âb33c¶FÆÂÒFÆÄ÷VâgV÷C·W6W#3"æFÆÂgV÷C²£´÷D¶W6WBgV÷C·´U47ÒgV÷C²ÂgV÷CµFW&ÖæFRgV÷C² ¢5&Vvöâ2225D%B¶öFuT6V7Föâ222f÷&ÓÖ¢b3#·6b3#¶WFòÖBfÆW2b3#¶wVFW6vç2b3#¶WF÷F"æ·`¢b33cµ&VçEvâÒuT7&VFRgV÷C´WFõF"bgV÷C²fײb33c·fW'6öâÂ33bÂ3Â2ÂR¢b33c´çWCÒuT7G&Ä7&VFTçWBgV÷C³gV÷C²ÂcÂ#"ÂC2Â#¢b33c´6V6¶&÷ÒuT7G&Ä7&VFT6V6¶&÷gV÷CµW6RgV÷C²Â#ÂSBÂrÂrÂ&Dõ"b33c´%5ô4T4´$õÂb33c´%5ôUDô4T4´$õÂb33c´%5õ$tD%UEDôâÂb33c´%5õ$tBÂb33cµu5õD%5Dõ¢b33c´Æ&VÃÒuT7G&Ä7&VFTÆ&VÂgV÷CµF"Ö÷VçBgV÷C²ÂrÂ#RÂc"Âr¢b33c´Æ&"ÒuT7G&Ä7&VFTÆ&VÂgV÷Cµ&W72F÷vâ'&÷rFòW6RvVâW6R26V6¶VBgV÷C²ÂCÂÂ#SÂrÂb33cµ55ô4TåDU"¢4VæE&Vvöâ222TäB¶öFuT6V7Föâ220 ¤uT6WDöäWfVçBb33c´uTôUdTåEô4Äõ4RÂgV÷Cµ7V6ÄWfVçG2gV÷C²¤uT6WDöäWfVçBb33c´uTôUdTåEôÔäÔ¤RÂgV÷Cµ7V6ÄWfVçG2gV÷C²¤uT6WDöäWfVçBb33c´uTôUdTåEõ$U5Dõ$RÂgV÷Cµ7V6ÄWfVçG2gV÷C² ¢b33c¶öàÒG&7&VFTFVÒgV÷C´WFõF"öâgV÷C²ÂÓÂÓ¢b33c¶öfbÒG&7&VFTFVÒgV÷C´WFõF"öfbgV÷C²ÂÓÂÓÂ¥G&FVÕ6WE7FFRÓÂb33cµE$ô4T4´TB¥G&7&VFTFVÒgV÷C²gV÷C²¢b33cµG&WFFVÒÒG&7&VFTFVÒgV÷C´WBgV÷C² ¥G&6WDöäWfVçBb33cµE$ôUdTåEõ$Ô%DõT$ÄRÂgV÷CµG&WfVçG2gV÷C²¥G&FVÕ6WDöäWfVçBb33c¶öâÂgV÷CµG&WfVçG2gV÷C²¥G&FVÕ6WDöäWfVçBb33c¶öfbÂgV÷CµG&WfVçG2gV÷C²¥G&FVÕ6WDöäWfVçBb33cµG&WFFVÒÂgV÷CµG&WfVçG2gV÷C²  ¥G&6WE7FFR¥G&6WD6Æ6²b ¤uT6WE7FFR5uõ4õr ¥vÆR b&DäBuT7G&Å&VBb33c´6V6¶&÷Âb33c´uTô4T4´TBÒb33c´uTô4T4´TBFVà G&FVÕ6WE7FFRb33c¶öâÂb33cµE$ô4T4´TB G&FVÕ6WE7FFRb33c¶öfbÂb33cµE$õTä4T4´TB bô5&W76VBgV÷C³#gV÷C²Âb33c¶FÆÂFVà FEF" VæD` VÇ6P G&FVÕ6WE7FFRb33c¶öâÂb33cµE$õTä4T4´TB G&FVÕ6WE7FFRb33c¶öfbÂb33cµE$ô4T4´TB VæD`  6ÆVWC¥tVæ@ ¤gVæ2FEF"²Fæ·2Fò&6&B&ö&W'G6öà¢Æö6Âb33c·F&6÷VçBÒçVÖ&W"uT7G&Å&VBb33c´çWC¢Æö6Âb33c·6VæG7G&ærÒb33·µUÒb33°¢Æö6Âb33c¶f÷'f ¢f÷"b33c¶f÷'f"ÒFòb33c·F&6÷Vç@¢b33c·6VæG7G&ærf׳Òb33·µD'Òb33°¢æW@¢b33c·6VæG7G&ærf׳Òb33·´Dõtç×´ôÔWÒb33°¢6VæBb33c·6VæG7G&ær¤VæDgVæ0 £·FW7@£·FW7@£·FW7@ ¤gVæ27V6ÄWfVçG2¢6VÆV7@¢66RuTô5E$ÄBÒb33c´uTôUdTåEô4Äõ4P¢FW&ÖæFR ¢66RuTô5E$ÄBÒb33c´uTôUdTåEôÔäÔ¤P¢´×6t&÷ÂgV÷CµvæF÷rÖæÖ¦VBgV÷C²ÂgV÷C´CÒgV÷C²fײuTô5E$ÄBfײgV÷C²väæFÆSÒgV÷C²fײuTõtääDÄR vå6WE7FFRb33cµ&VçEvâÂgV÷C²gV÷C²Â5uôDR G&F67&DæÖRÂgV÷C¶2&VVâÖæצVBâF÷V&ÆV6Æ6²W&RFò&W7F÷&RgV÷C²Â¢¢66RuTô5E$ÄBÒb33c´uTôUdTåEõ$U5Dõ$P¢´×6t&÷ÂgV÷CµvæF÷r&W7F÷&VBgV÷C²ÂgV÷C´CÒgV÷C²fײuTô5E$ÄBfײgV÷C²väæFÆSÒgV÷C²fײuTõtääDÄR¢VæE6VÆV7@¢¤VæDgVæ0 ¤gVæ2G&WfVçG2¢6VÆV7@¢66RE$ôBÒb33cµE$ôUdTåEõ$Ô%DõT$ÄP vå6WE7FFRb33cµ&VçEvâÂgV÷C²gV÷C²Â5uõ4õr vå6WE7FFRb33cµ&VçEvâÂgV÷C²gV÷C²Â5uõ$U5Dõ$R G&F67&DæÖRÂgV÷C²gV÷C²Â VæE6VÆV7@ 7vF6E$ô@ 66Rb33c¶öà uT7G&Å6WE7FFRb33c´6V6¶&÷Âb33c´uTô4T4´TB 66Rb33c¶öf` uT7G&Å6WE7FFRb33c´6V6¶&÷Âb33c´uTõTä4T4´TB 66Rb33cµG&WFFVÐ FW&ÖæFR VæE7vF6¤VæDgVæ0 ¤gVæ2FW&ÖæFR FÆÄ6Æ÷6Rb33c¶FÆ W@¤VæDgVæ

A decision is a powerful thing

Share this post


Link to post
Share on other sites

Yeah, you're welcome. I love it when I can actually help people.

Share this post


Link to post
Share on other sites

:whistle: Yeah no joke

I got another question. Do you know how to grab text from a edit area without using ControlCommand or Send ? Basically, I think it would be rad to have the script above actually grab the user's highlighted text and then add tabs in front of it, instead of having to press the down arrow for every row.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

:whistle: Yeah no joke

I got another question. Do you know how to grab text from a edit area without using ControlCommand or Send ? Basically, I think it would be rad to have the script above actually grab the user's highlighted text and then add tabs in front of it, instead of having to press the down arrow for every row.

That can be done with a very small change to your code. In fact I think it simplifies things a bit.

Here is the changed code -

#cs -------------------------------------------------
    Author:   John Bailey
    Modifier:     name
    Date Modified:  07/05/2007
    ScriptFunction: This helps a lot to format script
    AutoIt Ver:     version
   
    NOTE: Thanks to Richard Robertson for the AddTab code revsion

    Script Version: 1.0.0 (base code).(improved/added features).(script errors corrected)
   
    Script Update History:

#ce -------------------------------------------------
Global $version = '1.0.0'


                #include <Constants.au3>
                #include <GUIConstants.au3>
                #Include <Misc.au3>
                Opt("WinSearchChildren", 1)
                Opt ("GUIOnEventMode", 1)
                Opt("TrayOnEventMode",1)
                Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.

Global $dll = DllOpen("user32.dll")
;HotKeySet("{ESC}", "Terminate")

#Region ### START Koda GUI section ### Form=i:\sai\auto-it files\gui designs\autotab.kxf
$ParentWin = GUICreate("AutoTab    v"&$version, 336, 131, 193, 115)
$Input1 = GUICtrlCreateInput("1", 160, 22, 43, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Use  ", 121, 54, 97, 17, BitOR($BS_CHECKBOX,$BS_AUTOCHECKBOX,$BS_RIGHTBUTTON,$BS_RIGHT,$WS_TABSTOP))
$Label1 = GUICtrlCreateLabel("Tab Amount", 97, 25, 62, 17)
$Label2 = GUICtrlCreateLabel("Press Down Arrow to use when Use is checked", 48, 99, 250, 17, $SS_CENTER)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
            
$on = TrayCreateItem("AutoTab on", -1, -1, 1)
$off = TrayCreateItem("AutoTab off", -1, -1, 1)
TrayItemSetState(-1, $TRAY_CHECKED)
TrayCreateItem("")
$TrayExititem = TrayCreateItem("Exit")

TraySetOnEvent  ($TRAY_EVENT_PRIMARYDOUBLE,"TrayEvents")
TrayItemSetOnEvent($on,"TrayEvents")
TrayItemSetOnEvent($off,"TrayEvents")
TrayItemSetOnEvent($TrayExititem,"TrayEvents")


TraySetState()
TraySetClick(16)

GUISetState(@SW_SHOW)

While 1
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) = $GUI_CHECKED Then
        TrayItemSetState($on, $TRAY_CHECKED)
        TrayItemSetState($off, $TRAY_UNCHECKED)
        If _IsPressed("09", $dll) Then;28 <- just detect TAB, what could be simpler?
            AddTab()
        EndIf
    Else
        TrayItemSetState($on, $TRAY_UNCHECKED)
        TrayItemSetState($off, $TRAY_CHECKED)
    EndIf
   
    Sleep(40)
WEnd

Func AddTab() ;

 Thanks to Richard Robertson
    Local $tabcount = Number(GUICtrlRead($Input1))

   if $tabcount <= 1 then return

    Local $sendstring = '';{UP}';no need for UP
    Local $forvar
    For $forvar = 1 To $tabcount-1
        $sendstring &= '{TAB}'
    Next
;to make sure the last character sent is not TAB, add left and right
;might be better ways to do this
    $sendstring &= '{LEFT}{RIGHT}';{DOWN}{HOME}'
    Send($sendstring)
EndFunc

;test
;test
;test

Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Terminate()
           
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            ;MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            WinSetState($ParentWin, "", @SW_HIDE)
            TrayTip(@ScriptName, "has been minimzed. Doubleclick here to restore", 10, 0)
           
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
            ;MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
    EndSelect
   
EndFunc

Func TrayEvents()
    Select
       Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOUBLE
            WinSetState($ParentWin, "", @SW_SHOW)
            WinSetState($ParentWin, "", @SW_RESTORE)
            TrayTip(@ScriptName, "", 0)
    EndSelect
    Switch @TRAY_ID
        Case $on
            GUICtrlSetState($Checkbox1,$GUI_CHECKED)
        Case $off
            GUICtrlSetState($Checkbox1,$GUI_UNCHECKED)
        Case $TrayExititem
            Terminate()
    EndSwitch
EndFunc

Func Terminate()
    DllClose($dll)
    Exit
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

That can be done with a very small change to your code. In fact I think it simplifies things a bit.

Here is the changed code -

I don't think I asked my question correctly. I want to highlight text in, for instance, Notepad and then have a certain number of tabs added before each line of highlighted text in Notepad. Of course, I'm trying to do this without send('^c') or ControlCommand and "GetSelected" because those don't seem to do the trick.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

btw, the reason it was {down}{home} and the firing button 28 is that way I can simply press down and the line was on will be tabbed forward and then I'll be at the beginning of the next line and able to hit down again repeating the same action when I press down.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

btw, the reason it was {down}{home} and the firing button 28 is that way I can simply press down and the line was on will be tabbed forward and then I'll be at the beginning of the next line and able to hit down again repeating the same action when I press down.

Ah!

What I suggested would work in editors like Scite which is what I used to test my changes, but no use at all in Notepad.

I might be missing something but could you do the following?

Send ^x to cut the highlighted text. Then copy the text from the clipboard to an edit in your form (hidden say unless you want to fault find) and then read each line from the edit and paste it back but with the correct number of TABs first.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Ah!

What I suggested would work in editors like Scite which is what I used to test my changes, but no use at all in Notepad.

I might be missing something but could you do the following?

Send ^x to cut the highlighted text. Then copy the text from the clipboard to an edit in your form (hidden say unless you want to fault find) and then read each line from the edit and paste it back but with the correct number of TABs first.

I've tried something similar

Send('^c') ;even tried ('{CTRLDOWN}'&'c'&'{CTRLUP}')

Local $string = ClipGet()

Local $stringArray = StringSplit($string,@CR,'1')

_ArrayDisplay($stringArray)

Nothing new is placed in the clipboard.


A decision is a powerful thing

Share this post


Link to post
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
Sign in to follow this  
Followers 0