3mustgetbeers Posted November 25, 2011 Share Posted November 25, 2011 Hi, In the script I have, when you left click on the tray icon a gui is shown. The user enters a postcode into the gui & presses enter; an ini file is read for a corresponding value, copied to the clipboard and then hides. This all works great. The problem I have is that after pressing enter to complete the function as highlighted above; whenever the user presses the enter key, the function still runs. This is no good as it pretty much renders the clipboard unusable. Anyway, here is the code I have: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <Misc.au3> #include "constants.au3" #Include <GuiToolBar.au3> #include <Array.au3> Global Const $INI_Path = "" Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 3) TraySetState() TraySetClick(8) TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Search") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "On_Exit") $sToolTipText = "Tech Support Region Finder" TraySetToolTip($sToolTipText) Global $iIcon_X, $iIcon_Y _Locate_Icon() Local $GUI_Width = 65 Local $GUI_Height = 21 $Gui = GUICreate("TSRF", $GUI_Width+2, $GUI_Height+2, @DesktopWidth, @DesktopHeight, BitOR($WS_POPUP, $WS_THICKFRAME, $WS_SIZEBOX)) GUISetBkColor(0xFFFFFF) $Input1 = GUICtrlCreateInput("Post Code", 0, 0, 65, 21) GUIRegisterMsg(0x0084, "WM_NCHITTEST") $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "") $aWin = WinGetPos($GUI) WinMove($GUI, "", @DesktopWidth - $aWin[2], @DesktopHeight - $aWin[3] - $aTaskbar[3]) GUISetState(@SW_HIDE) While 1 if _IsPressed("0D") AND WinExists($Gui) Then $Input = GuiCtrlRead($Input1) $TechRegion = IniRead($INI_Path & "data.ini",$Input,"Tech","NOT FOUND") ClipPut($TechRegion) GUISetState(@SW_HIDE) EndIf WEnd Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Return $HTCAPTION EndFunc Func _Locate_Icon () Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "") $iIcon_X = $aPos[0] $iIcon_Y = $aPos[1] Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSysTray_ButCount = 0 Then Return For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1 Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber) If StringInStr($sText, $sToolTipText) > 0 Then $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSysTray_ButtonNumber) $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ExitLoop EndIf If $iSysTray_ButtonNumber = $iSysTray_ButCount - 1 Then Return 1 Next Return 0 EndFunc Func Search() GUISetState(@SW_SHOW) EndFunc Func On_Exit() Exit EndFunc I assume it is something to do with the while loop here: While 1 if _IsPressed("0D") AND WinExists($Gui) Then $Input = GuiCtrlRead($Input1) $TechRegion = IniRead($INI_Path & "data.ini",$Input,"Tech","NOT FOUND") ClipPut($TechRegion) GUISetState(@SW_HIDE) EndIf WEnd Though as far as I can see I am telling it to wait for the user to press enter and when the GUI is active. I'm guessing that its something to do with the handle I am using for the gui?? Cheers Link to comment Share on other sites More sharing options...
water Posted November 25, 2011 Share Posted November 25, 2011 Though as far as I can see I am telling it to wait for the user to press enter and when the GUI is active. I'm guessing that its something to do with the handle I am using for the gui??Shouldn't you then replace WinExists with WinActive? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted November 25, 2011 Share Posted November 25, 2011 That _IsPressed probably shouldn't be there either. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
3mustgetbeers Posted November 25, 2011 Author Share Posted November 25, 2011 Thanks for the replies! Water; I've replaced with WinActive; however it does the exact same thing Admiral; I was under the assumption that I needed the _IsPressed so the gui knows when enter is pressed - or is there another way to do this?? Cheers! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2011 Moderators Share Posted November 25, 2011 3mustgetbeers,You need to use an Accelerator key to capture the ENTER press - it is like a HotKey but only works when your GUI is active. This seems to work as you require:expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include "constants.au3" #include <GuiToolBar.au3> #include <Array.au3> Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 3) Global Const $INI_Path = "" Global $iIcon_X, $iIcon_Y Local $GUI_Width = 65 Local $GUI_Height = 21 TraySetState() TraySetClick(8) TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "Search") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "On_Exit") $sToolTipText = "Tech Support Region Finder" TraySetToolTip($sToolTipText) _Locate_Icon() $Gui = GUICreate("TSRF", $GUI_Width + 2, $GUI_Height + 2, @DesktopWidth, @DesktopHeight, BitOR($WS_POPUP, $WS_THICKFRAME, $WS_SIZEBOX)) GUISetBkColor(0xFFFFFF) $Input1 = GUICtrlCreateInput("Post Code", 0, 0, 65, 21) ; Create a dummy control for the Accelerator to fire <<<<<<<<<<<<<<<<<<<<<<<< $hDummy = GUICtrlCreateDummy() $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "") $aWin = WinGetPos($Gui) WinMove($Gui, "", @DesktopWidth - $aWin[2], @DesktopHeight - $aWin[3] - $aTaskbar[3]) GUISetState(@SW_HIDE) ; Set accelerator for Enter to fire the dummy <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $AccelKeys[1][2] = [["{ENTER}", $hDummy]] GUISetAccelerators($AccelKeys) GUIRegisterMsg(0x0084, "WM_NCHITTEST") While 1 Switch GUIGetMsg() Case $hDummy ; If the dummy is fired <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $Input = GUICtrlRead($Input1) $TechRegion = IniRead($INI_Path & "data.ini", $Input, "Tech", "NOT FOUND") Beep() ; Just to show it only works when the GUI is active <<<<<< ClipPut($TechRegion) GUISetState(@SW_HIDE) EndSwitch WEnd Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Return $HTCAPTION EndFunc ;==>WM_NCHITTEST Func _Locate_Icon() Local $aPos = WinGetPos("[Class:Shell_TrayWnd]", "") $iIcon_X = $aPos[0] $iIcon_Y = $aPos[1] Local $hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") $aPos = ControlGetPos("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]") If @error Then Return $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] Local $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSysTray_ButCount = 0 Then Return For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1 Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSysTray_ButtonNumber) If StringInStr($sText, $sToolTipText) > 0 Then $aPos = _GUICtrlToolbar_GetButtonRect($hSysTray_Handle, $iSysTray_ButtonNumber) $iIcon_X += $aPos[0] $iIcon_Y += $aPos[1] ExitLoop EndIf If $iSysTray_ButtonNumber = $iSysTray_ButCount - 1 Then Return 1 Next Return 0 EndFunc ;==>_Locate_Icon Func Search() GUISetState(@SW_SHOW) EndFunc ;==>Search Func On_Exit() Exit EndFunc ;==>On_ExitAll clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
3mustgetbeers Posted November 25, 2011 Author Share Posted November 25, 2011 M23 Ahh! Never heard of accelerator key before but yes, worked a treat! Cheers! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 25, 2011 Moderators Share Posted November 25, 2011 3mustgetbeers, My pleasure. Useful things accelerator keys - I use them a lot. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now