Jump to content

Using One Hotkey Multiple Times


Recommended Posts

Hi,

I don't know whether this is the right place to put such an easy script, but maybe some people need something like that one day. :)

A friend of mine asked me, how to use one hotkey to call different funcs by hitting the key different times.

(The func put() is just to show, that different funcs are called. )

So here it is:

HotKeySet("a", "pressed")
Dim $i = 0, $PushTime = 1000

While 1
    Sleep(100)
WEnd

Func pressed()
    $i += 1
    Sleep($PushTime)
    Switch $i
        Case 1
            put(1)
        Case 2
            put(2)
        Case 3
            put(3)
        Case 4
            Exit (0)
    EndSwitch
    $i = 0
EndFunc   ;==>pressed

Func put($y)
    MsgBox(0, "Func called: ", "Nr: " & $y)
EndFunc   ;==>put

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Actually i didn't understand at first... i would press ( slowly) and kep getting a message box with "1"

but, then i realized you press the key 1 to 4 times within the $PushTime/sleep and the function is called with the corresponding # of 1 to 3... 4 exits

I have never used hotkeyset() like this

Good demo.... th.meger

8)

NEWHeader1.png

Link to comment
Share on other sites

same here valuater. Interesting use of hotkeyset.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

Hi,

thanks. It was kind of crackbrained. Firstly, I thought I have to take the time between hitting the hotkey but then I tried to create the buffer with the sleep command and it worked.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Shows another way of thinking outside the box. I was like "hrm how is he going to accomplish this"...once I saw the variable $PushTime and its location in the Sleep I knew it was the amount of times pressed.

I like it. I think it could be a useful script.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Hi,

that's so crazy. I tried to create some useful scripts like (see my sig) and I think there might be some people out there who uses them. :(

But no SmOke_N, garfrost, Valuater, BigDod, JSThePatriot and so on replied. :)

But posting this little script ... :D

Nevertheless, I'll keep on running. I love this forum!

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Hi,

that's so crazy. I tried to create some useful scripts like (see my sig) and I think there might be some people out there who uses them. :(

But no SmOke_N, garfrost, Valuater, BigDod, JSThePatriot and so on replied. :)

But posting this little script ... :D

Nevertheless, I'll keep on running. I love this forum!

So long,

Mega

I am in and out of the forums...many of your programs look good. I dont always have the time to check them out. I do appreciate the value you place on my opinion.

Lata,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

  • 4 months later...

Is this not a better way of doing it. this way you will not have to wait 1 second if you only pressed it once and you can keep going for as many presses as you like.

HotKeySet("a", "pressed")
Dim $i = 0, $PushTime = 200

While 1
    Sleep(100)
WEnd

Func pressed()
    $i += 1
    
    Do  
        $g=$i
        Sleep($PushTime)
        
    Until $g==$i
    
    Switch $i
        Case 1
            put(1)
        Case 2
            put(2)
        Case 3
            put(3)
        Case 4
            Exit (0)
    EndSwitch
    $i = 0
    
EndFunc   
Func put($y)
    MsgBox(0, "Func called: ", "Nr: " & $y)
EndFunc
Edited by Cue
Link to comment
Share on other sites

That works brilliantly Cue! It is much better without the wait

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

That works brilliantly Cue! It is much better without the wait

Hi,

what is better at the func from Cue? :)

Nice idea, but I still like my demo :P

HotKeySet("1", "pressed")
HotKeySet("2", "pressed1")

Dim $i = 0, $PushTime = 1000, $begin = 0

While 1
    Sleep(100)
WEnd

Func pressed()
    $begin = TimerInit()
    $i += 1
    Do
        $g = $i
        Sleep($PushTime)
    Until $g == $i
    Switch $i
        Case 1
            put(1)
        Case 2
            put(2)
        Case 3
            put(3)
        Case 4
            Exit (0)
    EndSwitch
    $i = 0
EndFunc   ;==>pressed

Func pressed1()
    $begin = TimerInit()
    $i += 1
    Sleep($PushTime)
    Switch $i
        Case 1
            put1(1)
        Case 2
            put1(2)
        Case 3
            put1(3)
        Case 4
            Exit (0)
    EndSwitch
    $i = 0
EndFunc   ;==>pressed1

Func put($y)
    ConsoleWrite("Nr: " & $y & " Cue : " & Round(TimerDiff($begin), 4) & @LF)
    ;MsgBox(0, "Func called: ", "Nr: " & $y)
EndFunc   ;==>put

Func put1($y)
    ConsoleWrite("Nr: " & $y & " Mega: " & Round(TimerDiff($begin), 4) & @LF)
    ;MsgBox(0, "Func called: ", "Nr: " & $y)
EndFunc   ;==>put1

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

When i tested them together Cues worked better because if i pressed the hotkey 3 times fastly it would always pop up saying "you pressed 3 times" but yours would sometimes say "you pressed 2 times" then "you pressed 1 times"

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

When i tested them together Cues worked better because if i pressed the hotkey 3 times fastly it would always pop up saying "you pressed 3 times" but yours would sometimes say "you pressed 2 times" then "you pressed 1 times"

Hi,

I see, no problem for me there. :) Both worked fine.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Thanks RazerM.

th.meger i did not mean to say that your function is written badly but i thought it would just be better to wait for a certain time between consecutive keys than wait 1 second for any amount of keypresses.

why did you write code to compare the two?

Edit: [ Your code for comparing the two will always give the same or a longer time for pressed() since you have used $PushTime with a value of 1000 for both functions]

Edit: [mistake on last edit]

Edited by Cue
Link to comment
Share on other sites

  • 1 year later...

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