Jump to content

About _IsPressed


Recommended Posts

Hello,

I have a huge script using _IsPressed for every control and action and I just noticed this in the Help File :

If calling this function repeatidly, should open 'user32.dll' and pass in handle.

Make sure to close at end of script

What's the use of doing this ?

Thanks.

Link to comment
Share on other sites

It speeds it up a little. Since the api _IsPressed is calling (GetAsyncKeyState) resides in user32 the UDF have to reopen it all the time to call the function. If you open it yourself it doesn't need too. However the speed impact of not opening it is not as big as people seem to think, because user32 is always loaded in autoit processes by default, so when the udf opens the dll again it just increment the internal reference count.

More info here.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

to check if a certain event is called..say a keypress..

Link to comment
Share on other sites

Ok, because in my code I had something messy like this...

While Not _IsPressed($_XButton1) And Not _IsPressed($_End); Loop ends with XButton1 or End

    [...]
        
    While Not (_IsPressed($_LButton) And Not _IsPressed($_Ctrl)) And Not (_IsPressed($_Enter) And Not _IsPressed($_Alt)) And Not _IsPressed($_XButton1) And Not _IsPressed($_End)

        [...]

        While _IsPressed($_LButton) Or  (_IsPressed($_Alt) And (_IsPressed($_Left) Or _IsPressed($_Up) Or _IsPressed($_Right) Or _IsPressed($_Down)))

            [...]

So now I did this...

Func OnAutoItExit()
    [...]
    DllClose($dll)
EndFunc

Global $dll = DllOpen("user32.dll")

While Not _IsPressed($_XButton1, $dll) And Not _IsPressed($_End, $dll); Loop ends with XButton1 or End

    [...]
        
    While Not (_IsPressed($_LButton, $dll) And Not _IsPressed($_Ctrl, $dll)) And Not (_IsPressed($_Enter, $dll) And Not _IsPressed($_Alt, $dll)) And Not _IsPressed($_XButton1, $dll) And Not _IsPressed($_End, $dll)

        [...]

        While _IsPressed($_LButton, $dll) Or  (_IsPressed($_Alt, $dll) And (_IsPressed($_Left, $dll) Or _IsPressed($_Up, $dll) Or _IsPressed($_Right, $dll) Or _IsPressed($_Down, $dll)))

            [...]

Sounds OK ?

Link to comment
Share on other sites

_Ispressed() works everytime for me even when i DONT open the DLL

Link to comment
Share on other sites

ah... multiplatform codes... or multiplatform Dlls... in any case YOUR right haha, i guess ill add DLLopen() in my scripts JUST to be GREEN :D

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...