Sign in to follow this  
Followers 0
Peentje

Problem with waiting-for-keypress function

9 posts in this topic

#1 ·  Posted (edited)

Hi, I've encountered the following problem with this particular section of a little script I made.

Here's the script:

for $__n1_ = 0 to 0 step 0

While 1
if _IsPressed(60) Then  ;wait for "0" press
EXitLoop
EndIf
WEnd

While 1
if _IsPressed(61) OR _IsPressed(62) OR _IsPressed(63) Then  ; 1, 2 or 3 pressed
EXitLoop
EndIf
WEnd

Select
    Case _IsPressed(61)
        Send ( '{TAB}' )
        Send ( '10' )
    Case _IsPressed(62)
        Send ( '{TAB}' )
        Send ( '20' )
    Case _IsPressed(63)
        Send ( '{TAB}' )
        Send ( '30' )
EndSelect

Next

Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
; $hexKey should entered as a string, don't forget the quotes!
; (yeah, layer. This is for you)
  
  Local $aR, $bO
  
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
  
  Return $bO
EndFunc ;==>_IsPressed

Now for the problem: the script starts when I press "0", then it waits for me to press 1,2 or 3 and then it sends some numbers, everything good so far. But when it repeats the For function it waits again for me to press the 0 key but then it doesn't wait till I press 1, 2 or 3 again, it just send the keypresses again I chose in the previous run (1,2,3), it doesn't wait for me to make a new choice. It's probably something stupid but can't seem to figure it out.

Hope somebody can help me out...

PS: Thanks to ezzetabi for the _IsPressed function.

Edited by Peentje

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm guessing your wanting a never ending loop

HotKeySet("{Esc}","_Exit")

$dll = DllOpen("user32.dll")
While 1
   While 1
        Sleep ( 50 )
      If _IsPressed("30",$dll) Then;wait for "0" press
         ExitLoop
      EndIf
   WEnd
   
   While 1
        Sleep ( 50 )
        Select
            Case _IsPressed("31",$dll) = 1
                Send('{TAB}')
                Send('10')
                ExitLoop
            Case _IsPressed("32",$dll) = 1
                Send('{TAB}')
                Send('20')
                ExitLoop
            Case _IsPressed("33",$dll) = 1
                Send('{TAB}')
                Send('30')
                ExitLoop
        EndSelect
   WEnd
WEnd

Func _Exit()
    DllClose($dll)
    Exit
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
; $hexKey must be the value of one of the keys.
; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc  ;==>_Is_Key_Pressed
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I'm guessing your wanting a never ending loop

HotKeySet("{Esc}","_Exit")

$dll = DllOpen("user32.dll")
While 1
   While 1
        Sleep ( 50 )
      If _IsPressed("30",$dll) Then;wait for "0" press
         ExitLoop
      EndIf
   WEnd
   
   While 1
        Sleep ( 50 )
        Select
            Case _IsPressed("31",$dll) = 1
                Send('{TAB}')
                Send('10')
                ExitLoop
            Case _IsPressed("32",$dll) = 1
                Send('{TAB}')
                Send('20')
                ExitLoop
            Case _IsPressed("33",$dll) = 1
                Send('{TAB}')
                Send('30')
                ExitLoop
        EndSelect
   WEnd
WEnd

Func _Exit()
    DllClose($dll)
    Exit
EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
; $hexKey must be the value of one of the keys.
; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc ;==>_Is_Key_Pressed
The problem stays, it waits for me to make a choice of 1,2,3 in the first run, but from the second run on it only waits for me to press 0, and then it immediately continues with the choice of 1,2,3 I made in the first run. If I chose 2 in the first run it immediately fills in "20" in the second run without letting me make a new choice...

Share this post


Link to post
Share on other sites

The problem stays, it waits for me to make a choice of 1,2,3 in the first run, but from the second run on it only waits for me to press 0, and then it immediately continues with the choice of 1,2,3 I made in the first run. If I chose 2 in the first run it immediately fills in "20" in the second run without letting me make a new choice...

I opened notepad and test the script, it worked fine for me.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

The problem stays, it waits for me to make a choice of 1,2,3 in the first run, but from the second run on it only waits for me to press 0, and then it immediately continues with the choice of 1,2,3 I made in the first run. If I chose 2 in the first run it immediately fills in "20" in the second run without letting me make a new choice...

The weird thing is, even after completely shutting down the script and restarting it, it STILL remembers what number (1,2,3) I chose, even in the first run it doesn't let me choose anymore, I really wonder how that is possible. Maybe there's something I have to reset in the script so that it doesn't remember what option I pressed in the previous run? I don't know, the fact that it remembers my choice even after restarting the script is very odd.

Share this post


Link to post
Share on other sites

I opened notepad and test the script, it worked fine for me.

I checked it in notepad and indeed, it works that way. But I'm using it for IE, and for some reason it remembers my choice when I use it there, any idea what could be the problem?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

HotKeySet("{Esc}","_Exit")
HotKeySet("0","_Start")

While 1
    Sleep ( 100 )
WEnd

Func _Start()
    TrayTip("Ready","Ready for 1,2,3",2000)
    HotKeySet("1","_One")
    HotKeySet("2","_Two")
    HotKeySet("3","_Three")
    HotKeySet("0")
EndFunc

Func _One()
    TrayTip("Ready","Ready for 0",2000)
    HotKeySet("1")
    HotKeySet("2")
    HotKeySet("3")
    Send('{TAB}')
    Send('10')
    HotKeySet("0","_Start")
EndFunc

Func _Two()
    TrayTip("Ready","Ready for 0",2000)
    HotKeySet("1")
    HotKeySet("2")
    HotKeySet("3")
    Send('{TAB}')
    Send('20')
    HotKeySet("0","_Start")
EndFunc

Func _Three()
    TrayTip("Ready","Ready for 0",2000)
    HotKeySet("1")
    HotKeySet("2")
    HotKeySet("3")
    Send('{TAB}')
    Send('30')
    HotKeySet("0","_Start")
EndFunc

Func _Exit()
    Exit
EndFunc

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

HotKeySet("{Esc}","_Exit")
HotKeySet("0","_Start")

While 1
    Sleep ( 100 )
WEnd

Func _Start()
    TrayTip("Ready","Ready for 1,2,3",2000)
    HotKeySet("1","_One")
    HotKeySet("2","_Two")
    HotKeySet("3","_Three")
    HotKeySet("0")
EndFunc

Func _One()
    TrayTip("Ready","Ready for 0",2000)
    HotKeySet("1")
    HotKeySet("2")
    HotKeySet("3")
    Send('{TAB}')
    Send('10')
    HotKeySet("0","_Start")
EndFunc

Func _Two()
    TrayTip("Ready","Ready for 0",2000)
    HotKeySet("1")
    HotKeySet("2")
    HotKeySet("3")
    Send('{TAB}')
    Send('20')
    HotKeySet("0","_Start")
EndFunc

Func _Three()
    TrayTip("Ready","Ready for 0",2000)
    HotKeySet("1")
    HotKeySet("2")
    HotKeySet("3")
    Send('{TAB}')
    Send('30')
    HotKeySet("0","_Start")
EndFunc

Func _Exit()
    Exit
EndFunc
You tested this one in notepad? Doesn't do much over here :P 0,1,2,3 gives me no response and I pasted your code exactly in the script.

Share this post


Link to post
Share on other sites

You tested this one in notepad? Doesn't do much over here :P 0,1,2,3 gives me no response and I pasted your code exactly in the script.

Yep, tested and works.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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