playlet Posted August 15, 2009 Share Posted August 15, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
JScript Posted August 15, 2009 Share Posted August 15, 2009 Hello 'playlet',Try my old function: _Inkey()expandcollapse popup#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 Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
playlet Posted August 15, 2009 Author Share Posted August 15, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
JScript Posted August 16, 2009 Share Posted August 16, 2009 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: expandcollapse popup#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 Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
playlet Posted August 16, 2009 Author Share Posted August 16, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
JScript Posted August 17, 2009 Share Posted August 17, 2009 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 Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
playlet Posted August 17, 2009 Author Share Posted August 17, 2009 (edited) --- Edited August 18, 2016 by playlet Link to comment Share on other sites More sharing options...
AndreyS Posted December 10, 2012 Share Posted December 10, 2012 Tell me, please, how to alter this function so that it will not start another function, and the return period of inactivity? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now