Jump to content

hotkeyset and ispressed


Champak
 Share

Recommended Posts

From the title, what is the difference? I don't see it in the help.

_IsPressed just returns 1 or 0, representing True or False.

HotKeySet launches the passed function, whenever the passed key ( passed in code form ) is pressed.

You should try those examples in the AutoIt Help file - You click on the "Open this Script" button at the bottom of the place where _IsPressed is described.

To easily find "_IsPressed" in AutoIt Help, you can click on the Search tab which is in the left pane of the AutoIt Help window at the top of the pane, type-in or paste "_IsPressed" and hit the Enter key on your keyboard. Then you double-click on the result listed in the "Select topic" field which says "Function _IsPressed".

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

OK, I guess I get that. You use the ispressed if you are going to "wrap" whatever in an IF function, and you use the hotkeyset if you are going to "launch" a function.

Although that is what it is, I don't see the difference really. The way I see it, you can use either one in place of each other...it just depends on how you code it. So what am I not seeing? Is there somewhere where one will not work for something and the other will?

Edit NOTE: Well I found one place where ispressed fails over hotkey. If the sleep function is active, hotkey will still do what you want it to do, where ispressed wont....or did I just do something screwy?

Edited by Champak
Link to comment
Share on other sites

HotKeySet() usually governs over your whole script, in that when it is running, whenever the given key is pressed by the user, even if another window is active, the passed function in your script is called.

The _IsPressed function, all by itself, works like IsArray or IsInt in that it only ever returns true or false, and only does so when it is explicitly called.

If you still don't get it after reading AutoIt Help, and if English is your first language, and then if you are above the age of 15, then I might end up having to refer you to Verse 1 of the Canon of Valik listed below. :D

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

_IsPressed is a UDF and AutoIt is a work in progress, being less than 9 years old. But there are always work-arounds that are possible, and here is where creativity comes into play.

Once, I tried to use _IsPressed and later I found out that a function I found on the AutoIt forums would serve me better to discover if there was any user input - a mouse movement or click or a keyboard key struck. Here is the function and it works well for me:

;=================================================================================================
; erifash says using _IdleTicks() this way will exitloop on any keystrokes or mouse action ...
;   $last = 0
; While 1
;       $new = _IdleTicks()
;       If $new < $last Then
;           Exit
;       EndIf
;   $last = $new
; WEnd
;=================================================================================================
Func _IdleTicks()
    Local $aTSB
    Local $ticksSinceBoot
    Local $struct
    Local $ticksSinceIdle
    $aTSB = DllCall("kernel32.dll", "long", "GetTickCount")
    $ticksSinceBoot = $aTSB[0]
    $struct = DllStructCreate("uint;dword")
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
    $ticksSinceIdle = DllStructGetData($struct, 2)
    Return ($ticksSinceBoot - $ticksSinceIdle)
EndFunc ;==>_IdleTicks
Edited by Squirrely1

Das Häschen benutzt Radar

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...