Sign in to follow this  
Followers 0
gottygolly

Error with _Ispressed?

5 posts in this topic

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  :thumbsup:

#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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Mouse not working here. Nothing happens.

Edit. Ok, i see the error now

Edited by GordonFreeman

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yes, i think Firefox is right, when remove GuiGetMsg make it always fast. I put a sleep(100) to make it slow

#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 by GordonFreeman

Share this post


Link to post
Share on other sites

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.

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