Sign in to follow this  
Followers 0
mentosan

loop until Ctrl+C

11 posts in this topic

Hello guys

I'm building an AutoIt script where I want to use a loop :

Do

[statement]

Until it will read from the keyboard Ctrl+C ("^C")

Can you help me with that ?

Thank you

Share this post


Link to post
Share on other sites

you can use the hotkeyset, create an infinite while loop (while 1 ... wend)

call the function you want when ctrl-c is pressed (due to the hotkeyset)


In the beginning there was nothing and then even that exploded - anonymous

Share this post


Link to post
Share on other sites

Do
    Send( "^c" )
    Sleep( 30 )
    $text = ClipGet( )
Until "" <> $text

It is one of possibilities :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I didn't succeed to make it work. When I press Ctrl+C on the keyboard, the script will give this error:

% Invalid input detected at '^' marker.

and then will continue to loop

This is my code :

CODE

AutoItSetOption ( "WinTitleMatchMode" , 2)

#include <file.au3>

Dim $ipfile="IP.txt"

Dim $ipadress

HotKeySet('^C', "ExitProgram")

_FileReadToArray ($ipfile, $ipadress)

Run ("telnet " & $ipadress)

WinActivate("Telnet " & $ipadress)

WinWaitActive("Telnet " & $ipadress)

Send ("admin" & "{Enter}")

Send ("ena" & "{Enter}")

Send ("tmp_pwd" & "{Enter}")

While 1

Send ("show ip mobile binding summary" & "{Enter}")

WEnd

Func ExitProgram()

Exit (0)

EndFunc

Edited by mentosan

Share this post


Link to post
Share on other sites

Any help ? :)

Share this post


Link to post
Share on other sites

Thanks for that .

Do you know which code I shall use in the script to copy its output in a logfile?

Share this post


Link to post
Share on other sites

FileWrite("text.txt",$output)

if that is what you are asking for :)

Share this post


Link to post
Share on other sites

Can you tell us WHAT you are making?

If it is a script for key logging:

People would not be happy if you were trying to make a keylogger! :)

Easiest way I could think of:

CODE: AutoIt

===========

#include <misc.au3>

$dll = DllOpen("user32.dll")

Do

Sleep(10)

Until _IsPressed("11", $dll) And _IsPressed("43", $dll)

Keyloggers use that type of function (_isPressed) to record keys that were pressed

Do you know which code I shall use in the script to copy its output in a logfile?

Well this sounds like you are trying to make a keylogger output log file.

Share this post


Link to post
Share on other sites

I didn't succeed to make it work. When I press Ctrl+C on the keyboard, the script will give this error:

% Invalid input detected at '^' marker.

and then will continue to loop

This is my code :

CODE

AutoItSetOption ( "WinTitleMatchMode" , 2)

#include <file.au3>

Dim $ipfile="IP.txt"

Dim $ipadress

HotKeySet('^C', "ExitProgram")

_FileReadToArray ($ipfile, $ipadress)

Run ("telnet " & $ipadress)

WinActivate("Telnet " & $ipadress)

WinWaitActive("Telnet " & $ipadress)

Send ("admin" & "{Enter}")

Send ("ena" & "{Enter}")

Send ("tmp_pwd" & "{Enter}")

While 1

Send ("show ip mobile binding summary" & "{Enter}")

WEnd

Func ExitProgram()

Exit (0)

EndFunc

In the hotkeyset you wrote HotKeySet('^C', "ExitProgram") which will cause an error when you're using these: ' for the first parameter and these: " for the next.

Your script will work fine if you just write:

HotKeySet("^C", "ExitProgram") instead of

HotKeySet('^C', "ExitProgram")

Good Luck :)

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  
Followers 0