Jump to content

---


Recommended Posts

Hello 'playlet',

Try my old function: _Inkey()

#include-once
#Include <Misc.au3>

; #INDEX# ==========================================================================================================================================================
; Title .........: _InKey
; AutoIt Version : 3.2.10++
; Language ......: English
; Description ...: Pauses the script until any key has been pressed or mouse activity.
; ==================================================================================================================================================================

; #CURRENT# ========================================================================================================================================================
;_InKey
; ==================================================================================================================================================================

; #INTERNAL_USE_ONLY#===============================================================================================================================================
;
; ==================================================================================================================================================================


; #FUNCTION# =======================================================================================================================================================
; Name...........: _InKey
; Description ...: Pauses the script until any key has been pressed or mouse activity.
; Syntax.........: InKey( [ TimeOut = -1 [, MouseCheck = False ]] )
; Parameters ....: TimeOut      - [Optional] Timeout in seconds. After the timeout has elapsed the script will be continue.
;                                   The default is -1 (waits indefinitely for a keystroke).
;                  MouseCheck   - [Optional] If True, check mouse activity, default is False
; Requirement(s).:
; Return values .: Success - 1
;                  Failure - 0 If TimeOut
;                           -1 If error and set @error to 1
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......: Sleep and _IsPressed
; Link ..........:
; Example .......: _Inkey(5); Pauses script five seconds if no mouse activity or any key pressed...
; ==================================================================================================================================================================
Func _InKey($nTimeOut = -1, $bMouseCheck = False)
    Local $skeys[117] = [116, "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", "11", "12", "13", "14", "1B", "20", "21", _
            "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "30", "31", "32", "33", "34", "35", "36", _
            "37", "38", "39", "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F", "50", "51", "52", _
            "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", _
            "6A", "6B", "6C", "6D", "6E", "6F", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", _
            "7E", "7F", "80H", "81H", "82H", "83H", "84H", "85H", "86H", "87H", "90", "91", "A0", "A1", "A2", "A3", "A4", "A5"]
    Local $nTimer = TimerInit()
    If $bMouseCheck Then Local $nOldPos[2], $nCheckPos1, $nCheckPos2, $aMousePos = MouseGetPos(), $aMousePos2
    If $nTimeOut = -1 Then
        $nTimeOut = 2147483647
    Else
        $nTimeOut *= 1000
    EndIf
    
    While @error = 0
        If TimerDiff($nTimer) > $nTimeOut Then Return 0 ; Timed out
        
        For $i = 1 To $skeys[0]
            If _IsPressed($skeys[$i]) Then Return 1 ;_IsPressed ?
        Next
        
        If $bMouseCheck Then
            $nOldPos[0] = $aMousePos[0]
            $nOldPos[1] = $aMousePos[1]
            $aMousePos2 = MouseGetPos()
            $nCheckPos1 = $nOldPos[0] + $nOldPos[1]
            $nCheckPos2 = $aMousePos2[0] + $aMousePos2[1]
            
            If $nCheckPos1 <> $nCheckPos2 Then Return 1
        EndIf
        Sleep(50)
    WEnd
    Return SetError(1, 0, -1)
EndFunc   ;==>_InKey

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

This works, but I had to remove "01" and "02" from the code to disable left and right mouse key from activating it.

How can this be modified to start the timer only when some key was pressed? And if that time would be > $some_time, something else would be called.

Thanks, Playlet

Yes, see:

#include-once
#include <Misc.au3>

;_InKey( [ TimeOut [, MouseCheck [, AutoStart [, CallFunction ]]]] )
_InKey(5, False, False, "_FunctionToCall")

Func _FunctionToCall()
    MsgBox(4096, "Teste", "Teste ok")
EndFunc

; #INDEX# ==========================================================================================================================================================
; Title .........: _InKey
; AutoIt Version : 3.2.10++
; Language ......: English
; Description ...: Pauses the script until any key has been pressed or mouse activity.
; ==================================================================================================================================================================

; #CURRENT# ========================================================================================================================================================
;_InKey
; ==================================================================================================================================================================

; #INTERNAL_USE_ONLY#===============================================================================================================================================
;
; ==================================================================================================================================================================


; #FUNCTION# =======================================================================================================================================================
; Name...........: _InKey
; Description ...: Pauses the script until any key has been pressed or mouse activity.
; Syntax.........: _InKey( [ TimeOut [, MouseCheck [, AutoStart [, CallFunction ]]]] )
; Parameters ....: TimeOut      - [Optional] Timeout in seconds. After the timeout has elapsed the script will be continue.
;                                   The default is -1 (waits indefinitely for a keystroke).
;                  MouseCheck   - [Optional] If True, check mouse activity, default is False
; Requirement(s).:
; Return values .: Success - 1
;                  Failure - 0 If TimeOut
;                           -1 If error and set @error to 1
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......: Sleep and _IsPressed
; Link ..........:
; Example .......: _Inkey(5); Pauses script five seconds if no mouse activity or any key pressed...
; ==================================================================================================================================================================
Func _InKey($nTimeOut = -1, $bMouseCheck = False, $lAutoStart = True, $sCallFunction = "")
    Local $skeys[117] = [116, "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", "11", "12", "13", "14", "1B", "20", "21", _
            "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "30", "31", "32", "33", "34", "35", "36", _
            "37", "38", "39", "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F", "50", "51", "52", _
            "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", _
            "6A", "6B", "6C", "6D", "6E", "6F", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", _
            "7E", "7F", "80H", "81H", "82H", "83H", "84H", "85H", "86H", "87H", "90", "91", "A0", "A1", "A2", "A3", "A4", "A5"]
    Local $nTimer, $iKeyPressed = 0
    If $bMouseCheck Then Local $nOldPos[2], $nCheckPos1, $nCheckPos2, $aMousePos = MouseGetPos(), $aMousePos2
    If $nTimeOut = -1 Then
        $nTimeOut = 2147483647
    Else
        $nTimeOut *= 1000
    EndIf
    
    If Not $lAutoStart Then
        While $iKeyPressed = 0
            For $i = 1 To $skeys[0]
                If _IsPressed($skeys[$i]) Then
                    $iKeyPressed = 1
                    ExitLoop
                EndIf
            Next
            Sleep(50)
        WEnd
    EndIf
    Sleep(200)
    
    $nTimer = TimerInit()
    While @error = 0
        If TimerDiff($nTimer) > $nTimeOut Then
            If $sCallFunction <> "" Then Call($sCallFunction)
            Return 0 ; Timed out
        EndIf
        
        For $i = 1 To $skeys[0]
            If _IsPressed($skeys[$i]) Then Return 1 ;_IsPressed ?
        Next
        
        If $bMouseCheck Then
            $nOldPos[0] = $aMousePos[0]
            $nOldPos[1] = $aMousePos[1]
            $aMousePos2 = MouseGetPos()
            $nCheckPos1 = $nOldPos[0] + $nOldPos[1]
            $nCheckPos2 = $aMousePos2[0] + $aMousePos2[1]
            
            If $nCheckPos1 <> $nCheckPos2 Then Return 1
        EndIf
        Sleep(50)
    WEnd
    Return SetError(1, 0, -1)
EndFunc   ;==>_InKey

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

Nice... and about this part?

For $i = 1 To $skeys[0]
            If _IsPressed($skeys[$i]) Then
                _InKey(5, False, False, "_FunctionToCall")
                Return 1 ;_IsPressed ?
            EndIf
        Next

_InKey(5, False, False, "_FunctionToCall") Only call your own function...

Change to: _InKey(5, False, False, $sCallFunction)

jscript.

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • 3 years later...

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