Jump to content

HotKeySet using same button to call out 2 different functions


Recommended Posts

I currently have two functions, each being called out by a hotkeyset. In this case it is F4 calling out function1() and F6 calling out function2(). I would like to make it where if I press F4 two times it will execute function1(). If I press it three times it will execute function2(). If there is any other key stroke made then it will reset the count. This way I can then use F6 for something else. Is something like this even possible?

Link to comment
Share on other sites

I currently have two functions, each being called out by a hotkeyset. In this case it is F4 calling out function1() and F6 calling out function2(). I would like to make it where if I press F4 two times it will execute function1(). If I press it three times it will execute function2(). If there is any other key stroke made then it will reset the count. This way I can then use F6 for something else. Is something like this even possible?

 

You're asking for, in essence, a keylogger. 

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

You're asking for, in essence, a keylogger. 

 

Are hotkeys not ok? We have samples all over the forum where functions are being called out by hotkeys. I am just looking to see if there is a way to consolidate my two hotkeys into 1. If so how would I go about doing it? Otherwise I will live with what I have and keep it one function per hotkey.

Link to comment
Share on other sites

  • Moderators

donhorn20,

I do not see this as any form of keylogger at all - all it uses are HotKeys. :)

I would do something like this:

Global $iFlag = 0

HotKeySet("q", "_Function")
HotKeySet("{ESC}", "On_Exit")

While 1
    Sleep(10)
WEnd

Func _Function()

    If $iFlag Then
        ; Increase flag count
        $iFlag += 1
        ConsoleWrite("Flag = " & $iFlag & @CRLF)
    Else
        ; Set Check function to run in 500ms
        AdlibRegister("_Checker", 1000) ; Adjust the time to suit <<<<<<<<<<
        ConsoleWrite("Timer Started" & @CRLF)
        ; Set flag
        $iFlag = 1
        ConsoleWrite("Flag = " & $iFlag & @CRLF)
    EndIf

EndFunc

Func _Checker()

    ; How many presses?
    Switch $iFlag
        Case 2
            ConsoleWrite("Running Func_2" & @CRLF)
            ;_Function_2()
        Case 3
            ConsoleWrite("Running Func_3" & @CRLF)
            ;_Function_3()
    EndSwitch
    ; Prevent Check function running again
    AdlibUnRegister("_Checker")
    ; Clear flag
    $iFlag = 0
    ConsoleWrite("Timer and flag reset" & @CRLF)

EndFunc

Func On_Exit()
    Exit
EndFunc

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

donhorn20,

I do not see this as any form of keylogger at all - all it uses are HotKeys. :)

I would do something like this:

Global $iFlag = 0

HotKeySet("q", "_Function")
HotKeySet("{ESC}", "On_Exit")

While 1
    Sleep(10)
WEnd

Func _Function()

    If $iFlag Then
        ; Increase flag count
        $iFlag += 1
        ConsoleWrite("Flag = " & $iFlag & @CRLF)
    Else
        ; Set Check function to run in 500ms
        AdlibRegister("_Checker", 1000) ; Adjust the time to suit <<<<<<<<<<
        ConsoleWrite("Timer Started" & @CRLF)
        ; Set flag
        $iFlag = 1
        ConsoleWrite("Flag = " & $iFlag & @CRLF)
    EndIf

EndFunc

Func _Checker()

    ; How many presses?
    Switch $iFlag
        Case 2
            ConsoleWrite("Running Func_2" & @CRLF)
            ;_Function_2()
        Case 3
            ConsoleWrite("Running Func_3" & @CRLF)
            ;_Function_3()
    EndSwitch
    ; Prevent Check function running again
    AdlibUnRegister("_Checker")
    ; Clear flag
    $iFlag = 0
    ConsoleWrite("Timer and flag reset" & @CRLF)

EndFunc

Func On_Exit()
    Exit
EndFunc

All clear? :)

M23

 

@ Melba23, this works great and is exactly what I was looking for. If I add a "Case 1" I could have the Function key perform it's default function correct? I understand I would have to define it but it is possible is it not? Thanks for the useful template. It works great.

Don

Link to comment
Share on other sites

  • Moderators

donhorn20,

You will probably have to disable the HotKeySet for the key, Send it, and then reenable the HotKeySet to get it to work - otherwise you just fire the HotKey again. ;)

Give it a try and let me now how you get on. :)

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

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