Sign in to follow this  
Followers 0
DragonBall

When I press keys, do a certain job

10 posts in this topic

I am trying to do the following:

When I type 0~9 or a~z or A~Z ( in fact more, like space, backspace...) in an editor ( for example : Notepad), then it will send "Ctrl + s " to save the file.

I have found a solution on internet as following:

While 1

sleep(100)

For $i = 32 to 127

if ( _IsPressed(Hex(8)) OR _IsPressed(Hex($i)) ) Then

Send("{F9}")

EndIf

Next

WEnd

But I don't like it, because each time when I type a letter, it will try to test the for loop i = 32 ~ 127. But I don't care which letter I typed, I just need to send "Ctrl + s" each time I type a letter, no matter which one. But I didn't find a way to do this.

It would be much better if it doesn't need to do sleep(100) during the while loop, instead it waits me to press the next key and send "Ctrl+S".

Share this post


Link to post
Share on other sites



This sounds like a keylogger and is not a subject that the AutoIt forums like to answer.

Please read the rules about posting these types of posts.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Also, I hope this script works only when I type in Notepad. I tried the following script, but it doesn't work:

While WinActive("Untitled - Notepad")

sleep(100)

For $i = 32 to 127

if ( _IsPressed(Hex(8)) OR _IsPressed(Hex($i)) ) Then

Send("^s")

EndIf

Next

WEnd

Share this post


Link to post
Share on other sites

This is not a keylogger because I don't want to know which key I typed.

Share this post


Link to post
Share on other sites

Then - why not write to the editor and when finished save it. Why would you want to save the file after each letter/char is entered?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Ok, the reason is : I use WinEdt as latex editor, but I like the "continuous preview" feature, see "Bakoma" for what this feature means. So I tried to make WinEdt has this feature. I use sumatraPDF as pdf viewer and set F9 as shortcut for compile by pdflatex.

Finally, I use autoit to send F9 when each letter is entered. Now, everything is very good. I just hope I could make it a little bit fast and fewer cpu resource consummation by improving the above script.

Share this post


Link to post
Share on other sites

If you want it faster, why dont you remove "sleep(100)" or reduce the time? the number is miliseconds.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

Sure, but it will use more cpu resource.....

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Your script closes by itself, dont you want to keep it running until you close it?

Edit: all you need is your script to simulate ctrl+s in each key you press right? and now it is simulating that when you press F9.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Check this one out, it checks for the notepad process instead of window, because the caption changes depending on the file that is open,

and when you press F9, it saves, meaning it presses Ctrl+S. It stays on tray, until you close it.

See how it works for you

#requireadmin
#Include <WinAPI.au3>

Local $save
$save = 0
HotKeySet ("{F9}", "save")

Func save()
    If ProcessExists ("Notepad.exe") then
    Send("^s")
    _WinAPI_Beep(1500, 100)
    EndIf
EndFunc

Do
sleep(100)
Until $save = 1

EDIT: oh, and the beep thingy is so that you know that the hotkey was pressed, otherwise you might not be sure, anyhow, if you dont want that, just delete it.

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

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