Delta01 Posted December 16, 2007 Share Posted December 16, 2007 (edited) 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 December 16, 2007 by Delta01 Link to comment Share on other sites More sharing options...
Nahuel Posted December 16, 2007 Share Posted December 16, 2007 (edited) 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 December 16, 2007 by Nahuel Link to comment Share on other sites More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 Well, your calling all types of functions at the same type when you press the hex key 70. Link to comment Share on other sites More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 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. Link to comment Share on other sites More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 And, you can't execute all those functions at once, one of the functions if not going to execute. Link to comment Share on other sites More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 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... Link to comment Share on other sites More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 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? Link to comment Share on other sites More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 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? Link to comment Share on other sites More sharing options...
Nahuel Posted December 16, 2007 Share Posted December 16, 2007 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 More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 (edited) 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 December 16, 2007 by JustinReno Link to comment Share on other sites More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 (edited) 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 December 16, 2007 by Delta01 Link to comment Share on other sites More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 Your Welcome! Link to comment Share on other sites More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 (edited) 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 December 16, 2007 by Delta01 Link to comment Share on other sites More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 Did you put $Var = 0 at the top of your script? If that doesn't work, try Global $Var = 0. Link to comment Share on other sites More sharing options...
Nahuel Posted December 16, 2007 Share Posted December 16, 2007 *sigh* Check the key press just once man! haha Link to comment Share on other sites More sharing options...
Nahuel Posted December 16, 2007 Share Posted December 16, 2007 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 More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 Yeah, forgot to say that. I did put Global $var = 0 I've checked the keys. Link to comment Share on other sites More sharing options...
Nahuel Posted December 16, 2007 Share Posted December 16, 2007 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 More sharing options...
Delta01 Posted December 16, 2007 Author Share Posted December 16, 2007 Works great. Thanks A LOT!! Link to comment Share on other sites More sharing options...
Nahuel Posted December 16, 2007 Share Posted December 16, 2007 No problem! all you gotta do now is add two more cases Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now