Jump to content
Sign in to follow this  
TheReveller

About _IsPressed

Recommended Posts

TheReveller

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.

Share this post


Link to post
Share on other sites
monoceres

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!

Share this post


Link to post
Share on other sites
CodyBarrett

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

Share this post


Link to post
Share on other sites
TheReveller

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 ?

Share this post


Link to post
Share on other sites
monoceres

Sounds OK ?

Yes. That is the intended use.


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

Share this post


Link to post
Share on other sites
CodyBarrett

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

Share this post


Link to post
Share on other sites
Richard Robertson

Yes it works. That doesn't make it efficient. In this case there's not a huge difference but with non-Windows dlls, opening it once instead of opening it over and over would be better.

Share this post


Link to post
Share on other sites
CodyBarrett

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

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  

×