gottygolly Posted April 16, 2014 Share Posted April 16, 2014 I've been trying to get this thing to work for a long time now and I finally managed to get it working properly but now I'm experiencing a different problem that I never noticed (Not sure if it was already there). When I use my arrow keys to move the box around it works fine but if I use my mouse (Like moving it) it makes the box go extremely fast. It is supposed to only add 1 pixel at a time so the box moves slower but when you move the mouse it acts like it moving 10+ pixels. Here's the code and thanks for any helpĀ expandcollapse popup#include<misc.au3> #include<file.au3> #include<guiconstants.au3> $gui = GUICreate("Gui",400,400) $input = GUICtrlCreateInput("",200,200,50,50) $box = GUICtrlCreateInput("",200,20,50,50) GUICtrlSetState($input,$gui_disable) GUICtrlSetState($box,$gui_disable) GUICtrlSetBkColor($box,0xFF0000) GUICtrlSetBkColor($input,0x000000) GUISetState() while 1 If _IsPressed("25") Then $cp = ControlGetPos($gui,"",$box) If down1() Then $cp2 = $cp[0] - 1 GUICtrlSetPos($box,$cp2,$cp[1]) EndIf EndIf If _IsPressed("26") Then $cp = ControlGetPos($gui,"",$box) If down2() Then $cp2 = $cp[1] - 1 GUICtrlSetPos($box,$cp[0],$cp2) EndIf EndIf If _IsPressed("27") Then $cp = ControlGetPos($gui,"",$box) If down3() Then $cp2 = $cp[0] + 1 GUICtrlSetPos($box,$cp2,$cp[1]) EndIf EndIf If _IsPressed("28") Then $cp = ControlGetPos($gui,"",$box) If down4() Then $cp2 = $cp[1] + 1 GUICtrlSetPos($box,$cp[0],$cp2) EndIf EndIf $msg = GUIGetMsg(1) Switch $msg[1] Case $gui Switch $msg[0] Case -3 Exit EndSwitch EndSwitch WEnd Func down1() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 200 And $b >= 200 And $c <= 251 And $d <= 250 Then Return False EndIf Return True EndFunc Func down2() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 250 And $b >= 200 And $c <= 250 And $d <= 251 Then Return False EndIf Return True EndFunc Func down3() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 200 And $b >= 199 And $c <= 250 And $d <= 250 Then Return False EndIf Return True EndFunc Func down4() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 199 And $b >= 200 And $c <= 250 And $d <= 250 Then Return False EndIf Return True EndFunc Link to comment Share on other sites More sharing options...
GordonFreeman Posted April 16, 2014 Share Posted April 16, 2014 (edited) Mouse not working here. Nothing happens. Edit. Ok, i see the error now Edited April 16, 2014 by GordonFreeman Frabjous Installation Link to comment Share on other sites More sharing options...
FireFox Posted April 16, 2014 Share Posted April 16, 2014 (edited) I guess it's due to GUIGetMsg, this last automatically idles the CPU when required.So I'm afraid you can't do anything unless using the OnEvent mode instead.Br, FireFox. Edited April 16, 2014 by FireFox Link to comment Share on other sites More sharing options...
GordonFreeman Posted April 16, 2014 Share Posted April 16, 2014 (edited) Yes, i think Firefox is right, when remove GuiGetMsg make it always fast. I put a sleep(100) to make it slow expandcollapse popup#include<misc.au3> #include<file.au3> #include<guiconstants.au3> $gui = GUICreate("Gui",400,400) GUISetState(@SW_DISABLE,$gui) $input = GUICtrlCreateInput("",200,200,50,50) $box = GUICtrlCreateInput("",200,20,50,50) GUICtrlSetState($input,$gui_disable) GUICtrlSetState($box,$gui_disable) GUICtrlSetBkColor($box,0xFF0000) GUICtrlSetBkColor($input,0x000000) GUISetState() Do If _IsPressed("25") Then $cp = ControlGetPos($gui,"",$box) If down1() Then $cp2 = $cp[0] - 1 GUICtrlSetPos($box,$cp2,$cp[1]) Sleep(100) EndIf EndIf If _IsPressed("26") Then $cp = ControlGetPos($gui,"",$box) If down2() Then $cp2 = $cp[1] - 1 GUICtrlSetPos($box,$cp[0],$cp2) Sleep(100) EndIf EndIf If _IsPressed("27") Then $cp = ControlGetPos($gui,"",$box) If down3() Then $cp2 = $cp[0] + 1 GUICtrlSetPos($box,$cp2,$cp[1]) Sleep(100) EndIf EndIf If _IsPressed("28") Then $cp = ControlGetPos($gui,"",$box) If down4() Then $cp2 = $cp[1] + 1 GUICtrlSetPos($box,$cp[0],$cp2) Sleep(100) EndIf EndIf Until 1=2 Func down1() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 200 And $b >= 200 And $c <= 251 And $d <= 250 Then Return False EndIf Return True EndFunc Func down2() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 250 And $b >= 200 And $c <= 250 And $d <= 251 Then Return False EndIf Return True EndFunc Func down3() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 200 And $b >= 199 And $c <= 250 And $d <= 250 Then Return False EndIf Return True EndFunc Func down4() $obj = ControlGetPos($gui,"",$input) $a = $cp[1] + $cp[3] $b = $cp[0] + $cp[2] $c = $cp[0] $d = $cp[1] If $a >= 199 And $b >= 200 And $c <= 250 And $d <= 250 Then Return False EndIf Return True EndFunc Edited April 16, 2014 by GordonFreeman Frabjous Installation Link to comment Share on other sites More sharing options...
gottygolly Posted April 17, 2014 Author Share Posted April 17, 2014 That's kind of weird. I used the code you provided Gordon and it works but I think it just goes too slow for my liking. Thanks for the help though. 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