Jump to content

Recommended Posts

Posted

So I've made this script that detects how long i have held down my left mouse button for and stores the information in an array and then sorts its using _ArraySort but the output is half sorted half broken.

Here's my script:

HotKeySet("{F1}","_exit")
#include <Misc.au3>
#include <Timers.au3>
#include <Array.au3>

Local $dll = DllOpen("user32.dll")
$on = False
Global $array[0]

While(1)
    If _IsPressed(01,$dll) Then
        $timer = _Timer_Init()
        While _IsPressed(01,$dll)
            Sleep(1)
        WEnd
        $time = _Timer_Diff($timer)
        _ArrayAdd($array,"Time: " & Floor($time) & " ms")
;~      ConsoleWrite("Time: " & Floor($time) & " ms" & @CRLF)
    EndIf
    Sleep(50)
WEnd

Func _exit()
    _ArraySort($array)
    _ArrayDisplay($array)
    Exit
EndFunc

And the output:

o5X6YHZ.png

See how its not sorted?  What is the problem here?

  • Moderators
Posted

TrashBoat,

_ArraySort sorts strings alphabetically - which is why you get what you do as a result. Save the values as numbers and it will sort numerically:

_ArrayAdd($array, Floor($time))

And if you open the DLL, you should really use DLLClose as you exit to shut it down.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Moderators
Posted

TrashBoat,

Actually AutoIt will clear up after you automatically - but doing it yourself is a good habit to get into and can save problems later on when you really do need to do so (such as with many GDI functions).

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 7/26/2018 at 11:32 AM, TrashBoat said:

does me not closing the dll result in memory loss

Expand  

It's the other way around; if you suffer from memory loss you may forget to close the handle.;)

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
×
×
  • Create New...