Jump to content

Best way to (re)activate temporary hotkeys?


Guy_
 Share

Recommended Posts

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! :graduated:

#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 by Guy_
Link to comment
Share on other sites

  • Moderators

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! ;)

Global $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   ;==>_stripLastChar

The ConsoleWrite lines are just so that you can see what is going on - you can remove them without affecting the script. All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by Guy_
Link to comment
Share on other sites

  • Moderators

Guy_,

Or deactivate and reactivate the {F6} HotKey within _main to prevent multiple firings. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 :thumbsup:

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