Jump to content

Exit script if ECS key was pressed in 10 seconds


Recommended Posts

Hi everyone!

I have a script, i want exit script if ECS key was pressed in 10 seconds. In that time, if we don't press ECS key, the script goes on. Please help me write simple code with _IsPressed funtion.

Thank you so much!.

Link to comment
Share on other sites

HotKeySet() Would be easier/better, see this example:

HotKeySet("{ESC}", "_Quit")
$Timer = TimerInit()

Do
    Sleep(100)
Until TimerDiff($Timer) > 10000
HotKeySet("{ESC}")

ConsoleWrite("Script WAS NOT exited with esc" & @CRLF)

Func _Quit()
    ConsoleWrite("Script WAS exited with esc" & @CRLF)
    Exit
EndFunc
Link to comment
Share on other sites

Here is another example. This is a little more like what a script would really look like. Most scripts have while loops. This allows you to continue executing whatever you need to do while the timer is counting.

HotKeySet("{ESC}", "_Quit")
$Timer = TimerInit()
AdlibEnable("Adlib", 100)

While 1
    Sleep(50)
WEnd

Func _Quit()
    ConsoleWrite("Script WAS exited with esc" & @CRLF)
    Exit
EndFunc   ;==>_Quit

Func Adlib()
    If TimerDiff($Timer) >= 5000 Then
        HotKeySet("{ESC}", "Nothing")
        AdlibDisable()
        ConsoleWrite("Script WAS NOT exited with esc" & @CRLF)
        Exit
    EndIf
EndFunc   ;==>Adlib

Func Nothing()
EndFunc
Link to comment
Share on other sites

yet another example(it allows you to execute other code while and only exits ont he escape key if the script has been open for less than 10 seconds)

#include <misc.au3>

$timer = timerinit()
$check = 1

while 1
switch $check
    case 1
if timerdiff($timer) < 10000 and _ispressed('1B') then exit
if timerdiff($timer) >= 10000 then $check = 0
EndSwitch
;your code here
sleep(20)
wend

and another(pauses the script while waiting)

#include <misc.au3>

$timer = timerinit()

_escexitcheck()

while 1
;your code here
sleep(20)
wend

func _escexitcheck()
while timerdiff($timer) < 10000
if _ispressed('1B') then exit
wend
endfunc
Edited by IchBistTod

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

In my experience with adlib... well its shit, it pauses the main thread while executing the tasks its assigned.

and you over exaggerate, on a massive scale _ispressed() and timerdiff() are hardy "a lot" and nowhere near enough to cause lag. but none the less i revised it a bit....

But i suppose its really how one person views it compared to the next, in my opinion such simple tasks as I had before or such a simple task as I have now are.. well nothing.

Also I dont prefer to use hotkeyset() as ti deprives other applications of the hotkey or it fails to register if another app has actually registered the hotkey, even if only for a few second.

Edited by IchBistTod

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

  • Developers

In my experience with adlib... well its shit, it pauses the main thread while executing the tasks its assigned.

Huh? so you mean to say that when AutoIt3 is leaving the main processed code to performing the adlib function makes AutoIt3 shit?

I would agree with others that using a adlib function here would make you totally independent of the actual running script portion but it al depends on what you want to do in those initial 10 seconds.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

No I say adlib is shit, not autoit, I have implemented it in very large projects only to find that it made my application even slower, and greatly reduced its performance.

also refer to my statement about hotkeyset() int he above post witch was used in both examples before mine.

Edited by IchBistTod

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

  • Developers

No I say adlib is shit, not autoit, I have implemented it in very large projects only to find that it made my application even slower, and greatly reduced its performance.

Adlib is part of Autoit3 and do not blame your design flaws on autoit3.

Adlib works fine and does what it is advertised for.

I really don't mind if people voice their opinion but it would help when you know what you are talking about before making these statements.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Another way.

#Include <HotKey_17_beta.au3>

Global Const $VK_ESCAPE = 0x1B

Global $Timer = 0, $TimeOut = 10000

_HotKeyAssign($VK_ESCAPE, 'Quit', BitOR($HK_FLAG_NOOVERLAPCALL, $HK_FLAG_EXTENDEDCALL, $HK_FLAG_POSTCALL))

While 1
    Sleep(1000)
WEnd

Func Quit($iKey)
    If $iKey > 0 Then
        If $Timer = 0 Then
            $Timer = TimerInit()
        Else
            If TimerDiff($Timer) > $TimeOut Then
                Exit
            EndIf
        EndIf
    Else
        $Timer = 0
    EndIf
EndFunc   ;==>Quit

HotKey_17_beta.au3

Edited by Yashied
Link to comment
Share on other sites

I do know what I am talking about, I am voicing my opinion about adlib's performance in all the applications I have implemented it in(large complex apps) and it either makes them slower, or shows no performance increase when using versus sending $WM_COPYDATA to other processes created to communicate on a timer based delay in the main loop of the applications. 

adlib has shown me no improvements while using it, so in my opinion it is shit, ad adlib was not a part of autoit until the last few months, I have been using autoit for quite a while so I know.

And I don't blame any flaw I have on autoit, as stated above, I am stating that I can experience better, or the same performance by using multiple processes all communicating.

Also I never said adlib doesn't do what it says it does, I know it does what its supposed to just fine, but for a second time,I dont find it any better than other methods.

What really needs to be worked on instead of "make-shift" multi-threading (that can already be done better than adlib by other methods) is a real compiler, that instead of putting the script in with an interpreter, is to make it convert the code to C++ and compile it, I mean really, how hard can it be, you already have it interpreting to C++, so the only thing(and yes i know its a large task, but much smaller than starting from scratch) to do is make it turn the code into C++ then compile it with a command line C++ compiler. This would increase autoit's performance greatly. Or to actually make it multi thread(yes I know its stated that will not happen).

I can understand you may be offended by some things i say such as adlib is shit. But my opinion is that autoit should be revised to make it faster and more powerful(by changing from interpreted, to actual code conversion and compilation) than developing ways to simulate multi threading easier. 

That said, I'm sorry for offending you before, and if I have just now, and for getting this thread(more) off topic.

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

adlib has shown me no improvements while using it, so in my opinion it is shit, ad adlib was not a part of autoit until the last few months, I have been using autoit for quite a while so I know.

Obviously you have not been reading the help file and change log long enough. AdLib() has been in AutoIt3 since it's first release in 2003.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I had seen no implementations of it until the last few months, so if its been there that long, I stand corrected, however, it was not brought to my attention until the last few months.

[center][/center][center]=][u][/u][/center][center][/center]

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