Sign in to follow this  
Followers 0
Minikori

Wait for input

18 posts in this topic

Hey I'm trying to make my script wait for the user to press a key, then use that key in a function. It's the same concept as a custom hotkey, how to I do it?


For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites



Hey I'm trying to make my script wait for the user to press a key, then use that key in a function. It's the same concept as a custom hotkey, how to I do it?

You could use an infinite While loop with a giant branching statement that uses calls to _IsPressed() [found in Misc.au3 include] to see whether a valid key has been pressed.

As a small subset for a sample:

Func readKeypress()
    local $start = TimerInit()
    While 1
        If TimerDiff($start) > 10000 Then
            ;// stuff if your user took too long
        ElseIf _IsPressed(41) Then
            return("a")
        ElseIf _IsPressed(42) Then
            return("b")
        ElseIf _IsPressed(43) Then
            return("c")
        ElseIf _IsPressed(44) Then
            return("d")
        EndIf
                sleep(10)
        WEnd
EndFunc

this is just for letters a,b,c,d obviously, and yours would need to expand upon that to include all those that you wish to use.

Share this post


Link to post
Share on other sites

You could use an infinite While loop with a giant branching statement that uses calls to _IsPressed() [found in Misc.au3 include] to see whether a valid key has been pressed.

As a small subset for a sample:

Func readKeypress()
    local $start = TimerInit()
    While 1
        If TimerDiff($start) > 10000 Then
            ;// stuff if your user took too long
        ElseIf _IsPressed(41) Then
            return("a")
        ElseIf _IsPressed(42) Then
            return("b")
        ElseIf _IsPressed(43) Then
            return("c")
        ElseIf _IsPressed(44) Then
            return("d")
        EndIf
                sleep(10)
        WEnd
EndFunc

this is just for letters a,b,c,d obviously, and yours would need to expand upon that to include all those that you wish to use.

Alright, that will have to do for now, and if some has another way, that would be helpful.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

Hey I'm trying to make my script wait for the user to press a key, then use that key in a function. It's the same concept as a custom hotkey, how to I do it?

How many keys are you talking about? Why doesn't HotKeySet() work?

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

@Minikori...Why cant you use HotKeySet()?

Share this post


Link to post
Share on other sites

How many keys are you talking about? Why doesn't HotKeySet() work?

:P

If you can promise that this wouldn't be used as something malicious... I've got a modified version from someone else that will instantly check if any key is pressed. The problem is, it could easily be turned into a keylogger.

If you can describe what it is you're making and promise it's not to be used like this I will pm you the code :P

Share this post


Link to post
Share on other sites

Extremely CPU intensive way (also, Check4KeyPress Fn. should open 'user32.dll' and pass in it's handle to _IsKeyPress, but hey!)

#include <Misc.au3>
$HexKey = Check4KeyPress()
Msgbox(0, "Key was Pressed", "Key=" & $HexKey)


Func Check4KeyPress()
Local $number = StringSplit("01|02|04|05|06" & _
    "|08|09|0C|0D|10|11|12|13|14|1B|20|21|22" & _
    "|23|24|25|26|27|28|29|2A|2B|2C|2D|2E|30" & _
    "|31|32|33|34|35|36|37|38|39|41|42|43|44" & _
    "|45|46|47|48|49|4A|4B|4C|4D|4E|4F|50|51" & _
    "|52|53|54|55|56|57|58|59|5A|5B|5C|60|61" & _
    "|62|63|64|65|66|67|68|69|6A|6B|6C|6D|6E" & _
    "|6F|70|71|72|73|74|75|76|77|78|79|7A|7B" & _
    "|90|91|A0|A1|A2|A3|A4|A5", "|")

While 1
    For $i in $number
        If _IsPressed(String($i)) Then
            Return String($i)
        EndIf
    Next
Wend
    Return 0
EndFunc

Alright, that will have to do for now, and if some has another way, that would be helpful.

Share this post


Link to post
Share on other sites

I think they are looking to execute the function when ANY key is pressed, but use the key that was pressed in that function


Regards,Josh

Share this post


Link to post
Share on other sites

If you can promise that this wouldn't be used as something malicious... I've got a modified version from someone else that will instantly check if any key is pressed. The problem is, it could easily be turned into a keylogger.

If you can describe what it is you're making and promise it's not to be used like this I will pm you the code :P

It's a keep awake bot, so that on games like World of Warcraft, you won't go afk. I'm trying to make it customizable to what key it presses to keep it awake.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

It's a keep awake bot, so that on games like World of Warcraft, you won't go afk. I'm trying to make it customizable to what key it presses to keep it awake.

If the user has to sit there and press a key to keep it awake whats the point of the script? :P

Sorry I'm still confused :P

Share this post


Link to post
Share on other sites

If the user has to sit there and press a key to keep it awake whats the point of the script? :P

Sorry I'm still confused :P

You set your key then hit start, it then sends the key every certain amount of time(also specified by user)

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

Then where does the hotkey come in?


Regards,Josh

Share this post


Link to post
Share on other sites

You set your key then hit start, it then sends the key every certain amount of time(also specified by user)

The easiest way to do this by far is to just call the function every X amount of time

$Usertime = Int(GUICtrlRead($Input1)) ; 1000 = 1 second
AdlibEnable($Usertime, "My func")

Share this post


Link to post
Share on other sites

Then where does the hotkey come in?

i said same concept, not that i would be using a hotkey

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

So its not a hotkey at all... are you saying you just want one of the parameters in a function to be a key? Look up the Send() Function, and then just have a string with the key you will be sending as one of the parameters


Regards,Josh

Share this post


Link to post
Share on other sites

So its not a hotkey at all... are you saying you just want one of the parameters in a function to be a key? Look up the Send() Function, and then just have a string with the key you will be sending as one of the parameters

I know that, I needed help with getting the key that was pressed.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I know that, I needed help with getting the key that was pressed.

I PM'd you with the adlib stuff.

I'll be back in an hour or two...

Check this out though:

#include <GUIConstants.au3>
#include <GuiComboBoxEx.au3>
#include <String.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <misc.au3>
;




$HK_GUI = GUICreate("HotKey", 355, 81, 277, 197)
$Combo1 = GUICtrlCreateCombo("-None-", 8, 7, 110, 25)
GUICtrlSetData(-1, "Alt|Control|Shift")
$Combo2 = GUICtrlCreateCombo("Alt", 123, 7, 110, 25)
GUICtrlSetData(-1, "Control|Shift")
$Combo3 = GUICtrlCreateCombo("0", 237, 7, 110, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|ENTER|BACKSPACE|DELETE|UP|DOWN|LEFT|RIGHT|HOME|END|ESCAPE|INSERT|PGUP|PGDN|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|TAB|PRINTSCREEN|LWIN|RWIN|NUMPAD0|NUMPAD1|NUMPAD2|NUMPAD3|NUMPAD4|NUMPAD5|NUMPAD6|NUMPAD7|NUMPAD8|NUMPAD9")
$HK_Set = GUICtrlCreateButton("Set Hotkey", 62, 46, 87, 26, 0)
$HK_Cancel = GUICtrlCreateButton("Cancel", 186, 46, 87, 26, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $HK_Set
            
            $hotkeystring = ""
            If GUICtrlRead($Combo1) = "Alt" then 
                $hotkeystring = "!"
            ElseIf GUICtrlRead($Combo1) = "Control" then
                $hotkeystring = "^"
            ElseIf GUICtrlRead($Combo1) = "Shift" then
                $hotkeystring = "+"
            ElseIf GUICtrlRead($Combo1) = "-None-" then
                ; Doesn't add anything, but also doesn't error.
            Else
                $hotkeystring = "Error"
            EndIf
            
            ; Combo2
            If GUICtrlRead($Combo2) = "Alt" then 
                $hotkeystring &= "!"
                if $hotkeystring = "!!" Then $hotkeystring = "Error"
            ElseIf GUICtrlRead($Combo2) = "Control" then
                $hotkeystring &= "^"
                if $hotkeystring = "^^" Then $hotkeystring = "Error"
            ElseIf GUICtrlRead($Combo2) = "Shift" then
                $hotkeystring &= "+"
                if $hotkeystring = "++" Then $hotkeystring = "Error"
            Else
                $hotkeystring = "Error"
            EndIf
            
            if $hotkeystring <> "Error" Then
            
            $split = StringSplit("0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|ENTER|BACKSPACE|DELETE|UP|DOWN|LEFT|RIGHT|HOME|END|ESCAPE|INSERT|PGUP|PGDN|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|TAB|PRINTSCREEN|LWIN|RWIN|NUMPAD0|NUMPAD1|NUMPAD2|NUMPAD3|NUMPAD4|NUMPAD5|NUMPAD6|NUMPAD7|NUMPAD8|NUMPAD9", "|")
            For $I = 1 to $split[0]
                
                If GUICtrlRead($Combo3) = $split[$I] Then
                    $hotkeystring &= "{" & StringLower($split[$I]) & "}"
                    ExitLoop
                EndIf
                
                
            Next
            
            EndIf
            
            TrayTip("Hotkey", $hotkeystring, 1)
            HotKeySet($hotkeystring, "myfunc")
                

    EndSwitch
WEnd

Func myfunc()
    TrayTip("pressed", @HotKeyPressed, 1)
    
    EndFunc
Edited by Szhlopp

Share this post


Link to post
Share on other sites

I PM'd you with the adlib stuff.

I'll be back in an hour or two...

Check this out though:

#include <GUIConstants.au3>
#include <GuiComboBoxEx.au3>
#include <String.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <misc.au3>
;




$HK_GUI = GUICreate("HotKey", 355, 81, 277, 197)
$Combo1 = GUICtrlCreateCombo("-None-", 8, 7, 110, 25)
GUICtrlSetData(-1, "Alt|Control|Shift")
$Combo2 = GUICtrlCreateCombo("Alt", 123, 7, 110, 25)
GUICtrlSetData(-1, "Control|Shift")
$Combo3 = GUICtrlCreateCombo("0", 237, 7, 110, 25)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|ENTER|BACKSPACE|DELETE|UP|DOWN|LEFT|RIGHT|HOME|END|ESCAPE|INSERT|PGUP|PGDN|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|TAB|PRINTSCREEN|LWIN|RWIN|NUMPAD0|NUMPAD1|NUMPAD2|NUMPAD3|NUMPAD4|NUMPAD5|NUMPAD6|NUMPAD7|NUMPAD8|NUMPAD9")
$HK_Set = GUICtrlCreateButton("Set Hotkey", 62, 46, 87, 26, 0)
$HK_Cancel = GUICtrlCreateButton("Cancel", 186, 46, 87, 26, 0)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $HK_Set
            
            $hotkeystring = ""
            If GUICtrlRead($Combo1) = "Alt" then 
                $hotkeystring = "!"
            ElseIf GUICtrlRead($Combo1) = "Control" then
                $hotkeystring = "^"
            ElseIf GUICtrlRead($Combo1) = "Shift" then
                $hotkeystring = "+"
            ElseIf GUICtrlRead($Combo1) = "-None-" then
                ; Doesn't add anything, but also doesn't error.
            Else
                $hotkeystring = "Error"
            EndIf
            
            ; Combo2
            If GUICtrlRead($Combo2) = "Alt" then 
                $hotkeystring &= "!"
                if $hotkeystring = "!!" Then $hotkeystring = "Error"
            ElseIf GUICtrlRead($Combo2) = "Control" then
                $hotkeystring &= "^"
                if $hotkeystring = "^^" Then $hotkeystring = "Error"
            ElseIf GUICtrlRead($Combo2) = "Shift" then
                $hotkeystring &= "+"
                if $hotkeystring = "++" Then $hotkeystring = "Error"
            Else
                $hotkeystring = "Error"
            EndIf
            
            if $hotkeystring <> "Error" Then
            
            $split = StringSplit("0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|ENTER|BACKSPACE|DELETE|UP|DOWN|LEFT|RIGHT|HOME|END|ESCAPE|INSERT|PGUP|PGDN|F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|TAB|PRINTSCREEN|LWIN|RWIN|NUMPAD0|NUMPAD1|NUMPAD2|NUMPAD3|NUMPAD4|NUMPAD5|NUMPAD6|NUMPAD7|NUMPAD8|NUMPAD9", "|")
            For $I = 1 to $split[0]
                
                If GUICtrlRead($Combo3) = $split[$I] Then
                    $hotkeystring &= "{" & StringLower($split[$I]) & "}"
                    ExitLoop
                EndIf
                
                
            Next
            
            EndIf
            
            TrayTip("Hotkey", $hotkeystring, 1)
            HotKeySet($hotkeystring, "myfunc")
                

    EndSwitch
WEnd

Func myfunc()
    TrayTip("pressed", @HotKeyPressed, 1)
    
    EndFunc
Nice concept, I'll be back around when Szhlopp is.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Share this post


Link to post
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
Sign in to follow this  
Followers 0