Sign in to follow this  
Followers 0
Mario

Escape From If...then....endif

11 posts in this topic

I have some code looks like this:

if ....... then
.
.
.
.
.
.
.
.
EndIf

but between some commands i must check if an key pressed

now i must do:

#include <Misc.au3>
$dll = DllOpen("user32.dll")

if ....... then
    .
    If _IsPressed("11", $dll)=0 Then
        .
        .
        If _IsPressed("11", $dll)=0 Then
            .
            .
            .
        EndIf
    .
    .
    EndIf
    .
    .
EndIf

is there something like this?

#include <Misc.au3>
$dll = DllOpen("user32.dll")

if ....... then
.
If _IsPressed("11", $dll)=0 Then ExitIf
.
.
If _IsPressed("11", $dll)=1 Then ExitIf
.
.
.
.
EndIf

in complete code there are more lines and i must often check for keypressed

i mean: "goto" was not always bad :think:

any ideas?

thx and a happy weekend

sorry for the english

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is this what you want?

#include <Misc.au3>
$dll = DllOpen("user32.dll")

 While 1  
    Sleep(250) 
    If _IsPressed("41", $dll) Then
   ;what you want it to do. Example
      MsgBox(0, "A", "You pressed A")
    EndIf
    
      If _IsPressed("42", $dll) Then
      MsgBox(0, "B", "You pressed B")
  EndIf
Wend
DllClose($dll)
Edited by bucky002

Share this post


Link to post
Share on other sites

Or take a look at HotKeySet() in the helpfile. When the hotkey is pressed, it interrupts the script no matter where it's at (except for blocking functions), then you don't have to keep checking.


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

@bucky002: not that what im lookig for, sry :">

@neogia: after sending the Hotkey his Message( or whatever).. ist continues the programm at this point it has therefor broken :(

i want only break from the "if then" part without execute the following commands until "endif":think:

hope you understand what i mean

Share this post


Link to post
Share on other sites

You can do the following, but there might be a completely different and better way to do what you want:

#include <Misc.au3>
$dll = DllOpen("user32.dll")

While 1
if ....... then
.
If _IsPressed("11", $dll)=0 Then Break
.
.
If _IsPressed("11", $dll)=1 Then Break
.
.
.
.
EndIf

Break
Wend


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

hi exactly were did you guys get the commands for the _IsPressed key.

hehe I know them but were did you guys get them / locate them

01 Left mouse button 
  02 Right mouse button;does not works in my system... 
  04 Middle mouse button (three-button mouse) 
  05 Windows 2000/XP: X1 mouse button 
  06 Windows 2000/XP: X2 mouse button 
  08 BACKSPACE key 
  09 TAB key 
  0C CLEAR key 
  0D ENTER key 
  10 SHIFT key 
  11 CTRL key 
  12 ALT key 
  13 PAUSE key 
  14 CAPS LOCK key 
  1B ESC key 
  20 SPACEBAR 
  21 PAGE UP key 
  22 PAGE DOWN key 
  23 END key 
  24 HOME key 
  25 LEFT ARROW key 
  26 UP ARROW key 
  27 RIGHT ARROW key 
  28 DOWN ARROW key 
  29 SELECT key 
  2A PRINT key 
  2B EXECUTE key 
  2C PRINT SCREEN key 
  2D INS key 
  2E DEL key 
  30 0 key 
  31 1 key 
  32 2 key 
  33 3 key 
  34 4 key 
  35 5 key 
  36 6 key 
  37 7 key 
  38 8 key 
  39 9 key 
  41 A key 
  42 B key 
  43 C key 
  44 D key 
  45 E key 
  46 F key 
  47 G key 
  48 H key 
  49 I key 
  4A J key 
  4B K key 
  4C L key 
  4D M key 
  4E N key 
  4F O key 
  50 P key 
  51 Q key 
  52 R key 
  53 S key 
  54 T key 
  55 U key 
  56 V key 
  57 W key 
  58 X key 
  59 Y key 
  5A Z key 
  5B Left Windows key 
  5C Right Windows key 
  60 Numeric keypad 0 key 
  61 Numeric keypad 1 key 
  62 Numeric keypad 2 key 
  63 Numeric keypad 3 key 
  64 Numeric keypad 4 key 
  65 Numeric keypad 5 key 
  66 Numeric keypad 6 key 
  67 Numeric keypad 7 key 
  68 Numeric keypad 8 key 
  69 Numeric keypad 9 key 
  6A Multiply key 
  6B Add key 
  6C Separator key 
  6D Subtract key 
  6E Decimal key 
  6F Divide key 
  70 F1 key 
  71 F2 key 
  72 F3 key 
  73 F4 key 
  74 F5 key 
  75 F6 key 
  76 F7 key 
  77 F8 key 
  78 F9 key 
  79 F10 key 
  7A F11 key 
  7B F12 key 
  7C-7F F13 key - F16 key 
  80H-87H F17 key - F24 key 
  90 NUM LOCK key 
  91 SCROLL LOCK key 
  A0 Left SHIFT key 
  A1 Right SHIFT key 
  A2 Left CONTROL key 
  A3 Right CONTROL key 
  A4 Left MENU key 
  A5 Right MENU key

Thanks in advance

Share this post


Link to post
Share on other sites

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

from the dll i think and thats what it returns when its pressed i think

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I do this in a number of my scripts, or at least the inside of the loop, I use a while NOT (NUMBERS FROM PIXCHKSUM = PIXELGETCHECKSUM(X,Y,W,H,3)

and use this to break from it if it gets stuck, as I use this in a game tab changer for RuneScape, and I want it to click the tab to change to if the pixel checksum is not that of it being active, so if inactive choose it, else do nothing, and if I lose internet connection then i get logged off and it will never be equal to that number.

this is what i suggest you do, and I used a do loop until 0 so it does it once, that is what a do loop is good for.

You may still have better luck using the _ispressed but using the same do until loop idea I have here, get the best of both worlds.

Global $escape = 0

Func iftest()
HotKeySet("{esc}","Breaker")
Do
    If $escape = 1 Then
        HotKeySet("{esc}")
        $escape = 0
        ExitLoop
    EndIf
    If (YOUR TESTS HERE) Then
;YOUR CODE HERE
    EndIf
Until 0
EndFunc

Func Breaker()
    $escape = 1
    Return
EndFunc

Edit: Forgot EndFunc on the iftest() function

Edited by Onoitsu2

Things I have made:[font="Trebuchet Ms"]_CheckTimeBlock UDF(LT)MOH Call Ignore List (MOH = Modem On Hold)[/font]

Share this post


Link to post
Share on other sites

hi exactly were did you guys get the commands for the _IsPressed key.

hehe I know them but were did you guys get them / locate them

It's from MSDN Virtual-Key Codes

it's for function GetAsyncKeyState

I write it here only for let also other readers know about it :think:

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

thanks for your answers

You can do the following, but there might be a completely different and better way to do what you want:

#include <Misc.au3>
$dll = DllOpen("user32.dll")

While 1
if ....... then
.
If _IsPressed("11", $dll)=0 Then Break
.
.
If _IsPressed("11", $dll)=1 Then Break
.
.
.
.
EndIf

Break
Wend
doesn't work.....

i mean that would be the same as "Goto", that not more available in AutoItv3

now i make this:

#include <Misc.au3>
$dll = DllOpen("user32.dll")

While 1
.
.
If... Then
If _IsPressed ('11') =0 Then func1()
If _IsPressed ('11') =0 Then func2()
EndIf
.
.
Wend


Func func1()
.
.
EndFunc

Func func2()
.
.
EndFunc
Edited by Mario

Share this post


Link to post
Share on other sites

If you explained more of what you are doing then it may be possible to provide a "cleaner" work around for you, and/or even a solution.

IMHO,

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)

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