Sign in to follow this  
Followers 0
xKylex

Repeat a command until I press a certain button ?

26 posts in this topic

Ok, so I'm trying to set it up so it continually presses a button until I press a certain key. For example, let's say I wanted it to press F1 until I press Esc to cancel it. I have no clue whatsoever as to how to go about this. Please help. I'd like an answer in a script please. Thanks in advance.

Share this post


Link to post
Share on other sites



you would need to do something like this

HotkeySet("{Esc}", "Quit")
Func Quit()
     $oStop=1
EndFunc

Do
     Send("{F1}")
Until $oStop = 1

at least if i'm understanding your question correctly

Share this post


Link to post
Share on other sites

Ok, so I'm trying to set it up so it continually presses a button until I press a certain key. For example, let's say I wanted it to press F1 until I press Esc to cancel it. I have no clue whatsoever as to how to go about this. Please help. I'd like an answer in a script please. Thanks in advance.

Another harmless example. It really does help to search the help file and the forums.

#NoTrayIcon
HotKeySet("{ESC}", "ExitOut")
HotKeySet("{F1}", "Msg2DWise")
HotKeySet("^!{ESC}", "ThatRight")

MsgBox(0+64+262144,"Trifling... Completely Trifling", "Press F1 to demo and the ESC keys to quit.      ")

While 1
    Sleep(100)
WEnd

Func Msg2DWise()
    MsgBox(0+64+262144,"Trifling... Completely Trifling", "Have you searched the help file for your answer?      ")
    MsgBox(0+64+262144,"Trifling... Still Trifling", "Have you even searched the forums before      " & @CR & "posting this question?      ")
    While 1
        Send("{F1}")
        Sleep(100)
    WEnd
EndFunc

Func ThatRight()
    Exit 0
EndFunc

Func ExitOut()
    Msgbox(0+16+262144,"Trifling... No Doubt!", "Wanna Exit???" & @CR&@CR & "Press the ESC keys silly!")
EndFunc

Share this post


Link to post
Share on other sites

Another harmless example. It really does help to search the help file and the forums.

#NoTrayIcon
HotKeySet("{ESC}", "ExitOut")
HotKeySet("{F1}", "Msg2DWise")
HotKeySet("^!{ESC}", "ThatRight")

MsgBox(0+64+262144,"Trifling... Completely Trifling", "Press F1 to demo and the ESC keys to quit.      ")

While 1
    Sleep(100)
WEnd

Func Msg2DWise()
    MsgBox(0+64+262144,"Trifling... Completely Trifling", "Have you searched the help file for your answer?      ")
    MsgBox(0+64+262144,"Trifling... Still Trifling", "Have you even searched the forums before      " & @CR & "posting this question?      ")
    While 1
        Send("{F1}")
        Sleep(100)
    WEnd
EndFunc

Func ThatRight()
    Exit 0
EndFunc

Func ExitOut()
    Msgbox(0+16+262144,"Trifling... No Doubt!", "Wanna Exit???" & @CR&@CR & "Press the ESC keys silly!")
EndFunc
dam u. I actually ran that. I knew it seemed odd..

Share this post


Link to post
Share on other sites

dam u. I actually ran that. I knew it seemed odd..

LOL... oh now you can't be too upset with me, can you?? After all if you read and study the code you'll learn more than you asked. Isn't that what education should be; fun and rememberalbe? No harm intended, hopefully you can look back on this and chuckle!

If there's something in the code you don't understand, look up that command in the help file or ask us here. Have a good one xKylex.

--ss3

...

Share this post


Link to post
Share on other sites

Another harmless example. It really does help to search the help file and the forums.

#NoTrayIcon
HotKeySet("{ESC}", "ExitOut")
HotKeySet("{F1}", "Msg2DWise")
HotKeySet("^!{ESC}", "ThatRight")

MsgBox(0+64+262144,"Trifling... Completely Trifling", "Press F1 to demo and the ESC keys to quit.      ")

While 1
    Sleep(100)
WEnd

Func Msg2DWise()
    MsgBox(0+64+262144,"Trifling... Completely Trifling", "Have you searched the help file for your answer?      ")
    MsgBox(0+64+262144,"Trifling... Still Trifling", "Have you even searched the forums before      " & @CR & "posting this question?      ")
    While 1
        Send("{F1}")
        Sleep(100)
    WEnd
EndFunc

Func ThatRight()
    Exit 0
EndFunc

Func ExitOut()
    Msgbox(0+16+262144,"Trifling... No Doubt!", "Wanna Exit???" & @CR&@CR & "Press the ESC keys silly!")
EndFunc
You really shouldn't post code like that to noobs like good ol' kyle. It isn't polite. He new to the forum. You could have told him, the correct way to go about things. The right procedure. Did you? No. Whats funny is, you spent more time on that code, then a simple answer. The way you advertised it too. "another harmless example" Harmless?? In a way, it doesn't kill your computer, but it does create so many msgboxs, its just plain annoying! Why bother post, if it wont help to op??? Really??? He may be quite a quite person, like one of my best friends (also called Kyle). He is the type of person, who you can torment, and torment, and he will bottle up their anger. Until you push it too far, Its just the way he works. I'd watch yourself and your smart replies ssubirias3. Really. Help the other person like they have a right to be helped, or as far as I'm concerned, keep it in chat, or get out... I don't want you gone ssubirias3, but really, if you can't keep it sensible, i sure as hell don't want you on these forums.

Share this post


Link to post
Share on other sites

Bert, thank you. But yeah, I can look back and chuckle, in fact I am. But it didn't actually help me solve my problem, I still don't know how to do it. I've looked through the help section thing, couldn't find it though. I just need a code that basically means 'Repeat previous/following code until X button is pressed' then I think I can get the rest. Thanks in advance again, and Thank you ssubirias, I'ma edit the code you gave me a bit then send it to my friends :) .

Share this post


Link to post
Share on other sites

Bert, thank you. But yeah, I can look back and chuckle, in fact I am. But it didn't actually help me solve my problem, I still don't know how to do it. I've looked through the help section thing, couldn't find it though. I just need a code that basically means 'Repeat previous/following code until X button is pressed' then I think I can get the rest. Thanks in advance again, and Thank you ssubirias, I'ma edit the code you gave me a bit then send it to my friends :) .

Well duh! Knew I forgot something... I'm getting senile you see, and the worst bit is I'm only 15 :)

There are a few ways you could go about this.

There's this way:

#include <Misc.au3>

While 1
    ConsoleWrite ("> While Loop running.  Press Esc to Exit" & @CRLF)
; Some sort of code goes here... I just put a console write.
    If _IsPressed ("1B") Then
        ExitLoop
    EndIf
WEnd

ConsoleWrite ("> Loop Ended" & @CRLF)

or this way

#include <Misc.au3>

While Not _IsPressed ("1B")
    ConsoleWrite ("> While Loop running.  Press Esc to Exit" & @CRLF)
; Some sort of code goes here... I just put a console write.
WEnd

ConsoleWrite ("> Loop Ended" & @CRLF)

or...

#include <Misc.au3>

Do 
    ConsoleWrite ("> While Loop running.  Press Esc to Exit" & @CRLF)
; Some sort of code goes here... I just put a console write.
Until _IsPressed ("1B")

ConsoleWrite ("> Loop Ended" & @CRLF)

And finally,

HotKeySet ("{Esc}", "ExitFunc")

While 1
    ConsoleWrite ("> While Loop running.  Press Esc to Exit" & @CRLF)
WEnd

Func ExitFunc ()
ConsoleWrite ("> Loop Ended" & @CRLF)
Exit
EndFunc

That should get you well on your way :P

Share this post


Link to post
Share on other sites

Ok, I'm a bigger noob than I thought. Um...Thanks bert I suppose, but how do I set it up so it constantly presses F2 until I press ESC? BTW, I'm using the last code you posted. I'm a big noob, I need the exact code so I can copy and paste into an AutoIt script basically :) Thanks.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Imma see if you can figure this one out.

Open the script editor.

Press Ctrl+F

When the "Find" Dialog appears, type "F1" into the box and make sure "Whole word only" is unchecked.

When it highlights the "F1", change it to "F2"

Give it a try.

If it doesn't work, try again, and find the next instance of "F1"

Trust me, you can handle this one.

I'm not that dumb, I coulda done that. That script doesn't even have F1 in it though.

I'm thinking I might need the Do...Until action.

Is there anyway to take an .exe and convert it back into an editable AutoIt file?

Edited by xKylex

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I'm not that dumb, I coulda done that. That script doesn't even have F1 in it though.

lol

I didn't read all the way.

You called me out. :">

I didn't realize bert used consolewrite.

Just change this

ConsoleWrite ("> While Loop running.  Press Esc to Exit" & @CRLF)

to this

Send ("{F2}")

and @bert I understand and totally respect you standing up teh noobs, however, there is one part of your statement that i can not agree with

Really. Help the other person like they have a right to be helped, or as far as I'm concerned, keep it in chat, or get out...

my problem is that support here is a privilege, not a right. And had Kyle been a real ass(which he wasn't), he would not have earned his privilege to be helped. I agree that ssubirias3 was a little excessively poignant to someone who obviously has little to no scripting experience, there are much nicer and more appropriate ways of suggesting to check the helpfile, however, support is voluntary, and no one has the "right" to support. Edited by Paulie

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

lol

I didn't read all the way.

You called me out. :">

I didn't realize bert used consolewrite.

Just change this

ConsoleWrite ("> While Loop running.  Press Esc to Exit" & @CRLF)

to this

Send ("{F2}")
Wow, that's all I needed to do..? Lol, okay, well while I waited for a reply, I was kinda making my own code for it, and I came out with this:

HotKeySet ("{Esc}", "ExitFunc")

While 1
    Do 
        Send ("{w}")
        Until Send ( "{ESC}")
WEnd

Func ExitFunc ()
Exit
EndFunc

(I used 'w' because it would have noticeable and harmless results.)

But all it does is open then close, any suggestions?

BTW, thanks Happy Feet penguin guy (Sorry can't remember username :) )

Edited by xKylex

Share this post


Link to post
Share on other sites

Oh, I noticed what I did wrong :)

Share this post


Link to post
Share on other sites

Wow, that's all I needed to do..? Lol, okay, well while I waited for a reply, I was kinda making my own code for it, and I came out with this:

HotKeySet ("{Esc}", "ExitFunc")

While 1
    Do 
        Send ("{w}")
        Until Send ( "{ESC}")
WEnd

Func ExitFunc ()
Exit
EndFunc

(I used 'w' because it would have noticeable and harmless results.)

But all it does is open then close, any suggestions?

BTW, thanks Happy Feet penguin guy (Sorry can't remember username :P )

heh no problem, I'm sorry i didn't read. That was a 2:40 AM moment for me :)

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

So anyway, now I got it working (Thanks to the peeps that helped); You guys must be like, pretty intense scripter people. What kinda things can you guys make with AutoIt? Can you make viruses and stuff (Just wonder, I don't plan on it... :) ). With the GUI commands and stuff, could you actually create a full online game? That would be sweet, and if you could, I'd like to talk to you a bit more.. :P

Edited by xKylex

Share this post


Link to post
Share on other sites

@bert I understand and totally respect you standing up teh noobs, however, there is one part of your statement that i can not agree with

my problem is that support here is a privilege, not a right. And had Kyle been a real ass(which he wasn't), he would not have earned his privilege to be helped. I agree that ssubirias3 was a little excessively poignant to someone who obviously has little to no scripting experience, there are much nicer and more appropriate ways of suggesting to check the helpfile, however, support is voluntary, and no one has the "right" to support.

I agree 100% with you. It is a privilege, one that needs to be earned. I was getting at the right that Kyle had to be helped in a friendly manner. Not like ssubirias3 did. There is a way to give support to someone, and that was not it :). Thanks Paul.

Share this post


Link to post
Share on other sites

So anyway, now I got it working (Thanks to the peeps that helped); You guys must be like, pretty intense scripter people. What kinda things can you guys make with AutoIt? Can you make viruses and stuff (Just wonder, I don't plan on it... :) ) With the GUI commands and stuff, could you actually create a full online game? That would be sweet, and if you could, I'd like to talk to you a bit more.. :P

Of course you can create viruses. You can with any language. And people have made malicious programs, and people like them give AutoIt a bad name.

I have often thought of it. If you feel like you're up to a challenge, I will be happy to help you. I need something to do... Chat has its highs and lows...

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

So anyway, now I got it working (Thanks to the peeps that helped); You guys must be like, pretty intense scripter people.

"Pretty intense scripter people"

:) that was funny, and flattering! Thanks.

What kinda things can you guys make with AutoIt? Can you make viruses and stuff (Just wonder, I don't plan on it... :P ). With the GUI commands and stuff, could you actually create a full online game? That would be sweet, and if you could, I'd like to talk to you a bit more.. :)

Autoit can do alot of things. To be really automated about it,

AutoIt can:

* Provide a general-purpose scripting language for all Windows versions

* Simulate keystrokes (supports most keyboard layouts)

* Simulate mouse movements and clicks

* Move, resize and manipulate windows

* Interact directly with "controls" on a window (set/get text from edit controls, check boxes and radio buttons, select items in drop-down lists, etc.)

* Create complex user interfaces (GUIs)

* Work with the clipboard to cut/paste text items

* Provide a scriptable RunAs function for Windows 2000/XP/2003

:)

However, in regards to viruses and malware, the dev team has invested tons of time to having the compiler check scripts for malware. If they contain malware, they will immediately error out and fail. I personally am glad this has been instituted, because before it was, tons of people were getting autoit just to write viruses and hacks. and then they'd come here and pester us to help them. It was quite annoying.

EDIT: Shhhhh Bert!

Edited by Paulie

Share this post


Link to post
Share on other sites

Bert, when you said you often thought about it and would help me, did you mean about making a virus or a game? And I'm glad you can't make viruses in this too, I can understand the problems it would cause. Bert/Paulie, either of you got MSN?

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Sorry, It posted twice..

Edited by xKylex

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