Jump to content
Sign in to follow this  
Delta01

_IsPressed - Not recognizing

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Oh, thanks. So it won't work in a function call unless I put a while..wend in. Hmm, thanks..Looks like it's going in the main body.

Share this post


Link to post
Share on other sites

Dam. So I can't use _IsPressed and MouseGetPos()?

Is there any other way I can do it, i need to so that when you press SHIFT you get the X/Y Coord of the mouse...

Share this post


Link to post
Share on other sites

You can, but your calling all these different functions at the same time when you press the hex key 70. Why not just join them all together?

Share this post


Link to post
Share on other sites

Because I need to form a square if you will.

So you go over one point, press the hotkey. Move over another, press the hotkey etc etc.

Would HotKeySet() work here instead of Ispressed?

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

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  

×
×
  • Create New...