Guy_ Posted January 5, 2013 Posted January 5, 2013 (edited) I have a _main function triggered (again and again) with hotkey F6 It continually displays a tooltip for feedback. Each time I activate _main, I'd like a few temporary hotkeys to be activated for like 2 secs (here F7, F8) Each time I use F7 or F8, both should become active for 2 secs again ("reset timer" kinda). My example is working, but it probably is not "the professional way"...? I also wonder if there is a better way, so I won't get the tooltip flicker after 2 secs? Thanks for any superior tips! expandcollapse popup#include Global $names = _StringExplode( "Gregory,Melissa,Jonathan,Maureen,Patrick,David", ',' ) Global $random_name HotKeySet("{F6}", "_main") While 1 Sleep(100) WEnd Func _main() $random_name = $names [Random( 0, 5, 1 )] _startTempHotkeys() _showToolTip( $random_name ) EndFunc Func _showToolTip( $txt ) ToolTip( $txt, 1, 1 ) Sleep( 2000 ) ; leave temp hotkeys (re)activated for 2 secs Beep(1600, 85) ; temp hotkeys stopped _stopTempHotkeys() ToolTip( $txt, 1, 1 ) Sleep( 1000000 ) EndFunc Func _startTempHotkeys() HotKeySet("{F7}", "_surroundWithQuotes") HotKeySet("{F8}", "_stripLastChar") EndFunc Func _stopTempHotkeys() HotKeySet("{F7}") HotKeySet("{F8}") EndFunc ; temporary functions Func _surroundWithQuotes() $random_name = """" & $random_name & """" _startTempHotkeys() _showToolTip( $random_name ) EndFunc Func _stripLastChar() $random_name = StringTrimRight( $random_name, 1 ) _startTempHotkeys() _showToolTip( $random_name ) EndFunc Edited January 5, 2013 by Guy_
Moderators Melba23 Posted January 5, 2013 Moderators Posted January 5, 2013 Guy_,I am not sure that I would class this as the "professional way", but it is how I would approach the problem - and the tooltip does not flicker! expandcollapse popupGlobal $aNames[6] = ["Gregory", "Melissa", "Jonathan", "Maureen", "Patrick", "David"] Global $sRandom_Name, $iBegin HotKeySet("{F6}", "_main") While 1 Sleep(10) WEnd Func _main() $sRandom_Name = $aNames[Random(0, 5, 1)] $iBegin = TimerInit() ConsoleWrite("Timer set at " & @SEC & @CRLF) _startTempHotkeys() _showToolTip($sRandom_Name) While TimerDiff($iBegin) < 2000 Sleep(10) WEnd Beep(1600, 85) ; temp hotkeys stopped ConsoleWrite("Timer elapsed" & @CRLF) _stopTempHotkeys() EndFunc ;==>_main Func _showToolTip($txt) ToolTip($txt, 1, 1) EndFunc ;==>_showToolTip Func _startTempHotkeys() HotKeySet("{F7}", "_surroundWithQuotes") HotKeySet("{F8}", "_stripLastChar") EndFunc ;==>_startTempHotkeys Func _stopTempHotkeys() HotKeySet("{F7}") HotKeySet("{F8}") EndFunc ;==>_stopTempHotkeys ; temporary functions Func _surroundWithQuotes() $sRandom_Name = """" & $sRandom_Name & """" $iBegin = TimerInit() ConsoleWrite("Timer reset at " & @SEC & @CRLF) _showToolTip($sRandom_Name) EndFunc ;==>_surroundWithQuotes Func _stripLastChar() $sRandom_Name = StringTrimRight($sRandom_Name, 1) $iBegin = TimerInit() ConsoleWrite("Timer reset at " & @SEC & @CRLF) _showToolTip($sRandom_Name) EndFunc ;==>_stripLastCharThe ConsoleWrite lines are just so that you can see what is going on - you can remove them without affecting the script. All 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
Guy_ Posted January 7, 2013 Author Posted January 7, 2013 (edited) All clear? Yes, clear and functioning! Thank you for your Time[r] ;-) The only thing I have now, is that should I execute _main multiple times within the 2 secs, I'll get just as much beeps of timers running out. I guess I have to start _main with _Timer_KillTimer or something, and retrieve the handle from its value previously stored in some variable (have to read up on handles). Edited January 7, 2013 by Guy_
Moderators Melba23 Posted January 7, 2013 Moderators Posted January 7, 2013 Guy_,Or deactivate and reactivate the {F6} HotKey within _main to prevent multiple firings. 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
Guy_ Posted January 7, 2013 Author Posted January 7, 2013 Or deactivate and reactivate the {F6} HotKey within _main to prevent multiple firings. Yes, that too! To prevent it altogether, I gave _main a second temporary function as well (if pressed withing 2 secs). I added $hwnd after $iBegin (I hope I did that correctly...) $iBegin = TimerInit() $hwnd = WinGetHandle( WinGetTitle("[active]") ) And on top of _main I added: Local $hWnd If _Timer_Diff($iBegin) < 2000 Then _goDoSomething() _Timer_KillTimer( $hWnd, $iBegin ) Return EndIf It seems to work great so far. Thanks again
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