Jump to content

_IsPressed - Not recognizing


Delta01
 Share

Recommended Posts

Hi,

I'm making a script and my _IsPressed function isn't working. It works when I put it inside my While..WEnd statement but I also need it in a function statement, where it doesn't work.

My code is below, maybe I'm doing something wrong or maybe it doesn't work in functions?

If GuiCtrlRead($Custom) = $GUI_CHECKED Then
    MsgBox(64, "Screener v_1.0", "Custom screenshots only work in quadrilaterals (4 points) for example, a square." & @CRLF & "To set the four points please move the mouse over each point and press the SHIFT key (points must be drawn in a clockwise motion - Top right, Bottom right, Top left, Bottom left) Once all points are set the screenshot will be taken.")
    $Tip = ToolTip("Screener - Four points remain to be set", 0, 0)
    If _IsPressed(10, $dll) Then
    $FirstX = MouseGetPos(0)
    $Tip = ToolTip("Screener - Three points remain to be set", 0, 0)
EndIf
    If _IsPressed(10, $dll) Then
    $SecondX = MouseGetPos(0)
    $Tip = ToolTip("Screener - Two points remain to be set", 0, 0)
EndIf
    If _IsPressed(10, $dll) Then
    $FirstY = MouseGetPos(1)
    $Tip = ToolTip("Screener - One point remains to be set", 0, 0)
EndIf
    If _IsPressed(10, $dll) Then
    $SecondY = MouseGetPos(1)
    $Tip = ToolTip("Screener - All points are set", 0, 0)
    sleep(2000)
    $Tip = ToolTip("", 0, 0)
EndIf
EndIf
EndFunc

Thanks

EDIT: I've tried with various keys: the F keys, SHIFt, CTRL and ALT etc

Edited by Delta01
Link to comment
Share on other sites

You have any idea how fast you'd have to be so you can press a key before it finishes executing the function? You do it in a loop because you need to check continuously... ^_^

.edit.

And why do you check for the same key like 10 times? :)

If _IsPressed(10, $dll) Then
Edited by Nahuel
Link to comment
Share on other sites

What justing means, is that you should do something like this:

If _IsPressed(10) then

;Do all my stuff

endif

instead of:

If _IsPressed(10) then

;Do one thing

endif

If _IsPressed(10) then

;Do some other thing

endif

If _IsPressed(10) then

;Do some other thing

endif

The condition is the same (key is pressed). So check it just once!

Link to comment
Share on other sites

No, but you could use variables, Ex:

#Include <Misc.au3>

$Var = 0

While 1
If _Ispressed(01) Then
   If $Var = 0 Then
      Beep(10, 100)
      $Var += 1
      sleep(100)
   EndIf
   If $Var = 1 Then
       Beep(100, 100)
       $Var += 1
       sleep(100)
   EndIf
EndIf
WEnd

Untested, but should work. :) Try to put something like that in your code.

Edited by JustinReno
Link to comment
Share on other sites

I know I must sound like a complete moron but...

I can't do it all at once, I need them to press the key at each point so it needs to be pressed more than once.

If I do it all at once then the points wont be exactly where the user wants them

EDIT: Oh ok. Thanks guys i get it.

Edited by Delta01
Link to comment
Share on other sites

Ok, I tired that (code below) but it still won't work.

If _IsPressed(10, $dll) Then
        If $var = 0 Then
            MsgBox(0, "Screener v_1.0", "First coord is taken!")
    $FirstX = MouseGetPos(0)
    $Tip = ToolTip("Screener - Three points remain to be set", 0, 0)
    $var = 1
    EndIf
EndIf
    If _IsPressed(10, $dll) Then
        If $var = 1 Then
            MsgBox(0, "Screener v_1.0", "Second coord is taken!")
    $SecondX = MouseGetPos(0)
    $Tip = ToolTip("Screener - Two points remain to be set", 0, 0)
    $var = 2
    Endif
EndIf
Edited by Delta01
Link to comment
Share on other sites

Try this:

$var = 0
If _IsPressed(10, $dll) Then
    If $var = 0 Then
        MsgBox(0, "Screener v_1.0", "First coord is taken!")
        $FirstX = MouseGetPos(0)
        $Tip = ToolTip("Screener - Three points remain to be set", 0, 0)
        $var = 1
    EndIf
    If $var = 1 Then
        MsgBox(0, "Screener v_1.0", "Second coord is taken!")
        $SecondX = MouseGetPos(0)
        $Tip = ToolTip("Screener - Two points remain to be set", 0, 0)
        $var = 2
    EndIf
EndIf
Link to comment
Share on other sites

Sorry man, the code I just posted ain't working. Try this:

#include <Misc.au3>
$var = 0
While 1
    If _IsPressed(01) Then
        Switch $var
        Case  0 
            MsgBox(0, "Screener v_1.0", "First coord is taken!")
            $FirstX = MouseGetPos(0)
            $Tip = ToolTip("Screener - Three points remain to be set", 0, 0)
            $var = 1
        Case 1
            MsgBox(0, "Screener v_1.0", "Second coord is taken!")
            $SecondX = MouseGetPos(0)
            $Tip = ToolTip("Screener - Two points remain to be set", 0, 0)
            $var = 2
        EndSwitch
    EndIf
WEnd
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...