Jump to content

sending a key to notepad, wordpad, or any other editor


 Share

Recommended Posts

i know i can send keys using Send() but i only want it to be sent when user writes like this.

Line#1

Line#2

Line#3

and script sends the keys on pressing the first text like.

if pressed 'Line#1' than after pressing these keys script will add the second line to it.

Line#1 'this is just for test'

on entering 'Line#2' to the editor it will be like this.

Line#2 'this is the second line'

and son on...

Line#3 'continue'

Link to comment
Share on other sites

L0veUK

If I is correct has understood:

#include <GuiEdit.au3>

Run("Notepad")
WinWaitActive("[Class:Notepad]")
$hWnd = WinGetHandle("[Class:Notepad]")

$hEdit = ControlGetHandle("[Class:Notepad]", "", "Edit1")

AdlibEnable("_GetText")

While 1
    Sleep(100)
WEnd

Func _GetText()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    
    If StringRegExp($iText, "(?i)Line#1") Then
        AdlibDisable()
        $iText = StringRegExpReplace($iText, "(?i)Line#1", "Line#1 this is just for test")
        _GUICtrlEdit_SetText($hEdit, $iText)
        ControlSend($hWnd, "", $hEdit, "^{End}")
        Exit
    EndIf
EndFunc
Link to comment
Share on other sites

i know i can send keys using Send() but i only want it to be sent when user writes like this.

Line#1

Line#2

Line#3

and script sends the keys on pressing the first text like.

if pressed 'Line#1' than after pressing these keys script will add the second line to it.

Line#1 'this is just for test'

on entering 'Line#2' to the editor it will be like this.

Line#2 'this is the second line'

and son on...

Line#3 'continue'

Isn't this a simple case of needing a GUI with a few buttons whose actions send the keys? What am I missing? Try checking out the GUI section of the help file.
Link to comment
Share on other sites

L0veUK

If I is correct has understood:

#include <GuiEdit.au3>

Run("Notepad")
WinWaitActive("[Class:Notepad]")
$hWnd = WinGetHandle("[Class:Notepad]")

$hEdit = ControlGetHandle("[Class:Notepad]", "", "Edit1")

AdlibEnable("_GetText")

While 1
    Sleep(100)
WEnd

Func _GetText()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    
    If StringRegExp($iText, "(?i)Line#1") Then
        AdlibDisable()
        $iText = StringRegExpReplace($iText, "(?i)Line#1", "Line#1 this is just for test")
        _GUICtrlEdit_SetText($hEdit, $iText)
        ControlSend($hWnd, "", $hEdit, "^{End}")
        Exit
    EndIf
EndFunc
very good job rasim, Thanks dude!

but it will only work in Notepad and i want to use this function everywhere.

Link to comment
Share on other sites

If you are talking of using it in anything, then you are talking about a keylogger, and that is a No No No. Don't ask for it, don't hint at it, nothing.

i am talking about sending keys to make my work easy, where did i asked for recording them?

You care to explain what you have in mind for this "i want to use this function everywhere" thing?

it means whenever i want to write a line i will only write my secret word and the line will be completed automatically. how it sounds like a kelogger? you are a MVP with more than 4,000 posts... Edited by L0veUK
Link to comment
Share on other sites

very good job rasim, Thanks dude!

but it will only work in Notepad and i want to use this function everywhere.

You need to go through AutoIt 1-2-3 and learn how to use search. What you're trying to do is elementary and covered pretty exhaustively. Learn the language to the point where you can describe what you want to do, and then we can help you a lot more effectively when you encounter something that's difficult. :mellow:

Hotkeys are pretty much a core concept in AutoIt... press a button, make something happen. Instead of typing a magic word, you'd just press shift+F1 and your function will execute, or something like that. To do anything useful with your idea, you need to learn how to implement it. Things like which window is active when you activate the function, and so on. Without knowing the foundation, all the neat ideas you have will never be implemented unless someone else codes it, like rasim.

Link to comment
Share on other sites

i am talking about sending keys to make my work easy, where did i asked for recording them?

it means whenever i want to write a line i will only write my secret word and the line will be completed automatically. how it sounds like a kelogger? you are a MVP with more than 4,000 posts...

Look, you asked for it to be used everywhere. Which means ANY APPLICATION you type in text. Lets take a look ar your first post:

i know i can send keys using Send() but i only want it to be sent when user writes like this.

Well, it says "user" which means someone other than you.

very good job rasim, Thanks dude!

but it will only work in Notepad and i want to use this function everywhere.

You imply there you want to use it in ANY application you type.

From the looks of it, you are being misleading. Your last thread was locked for you would not give a strait answer, and was misleading. Here, your obviously doing it again. Again, you give me reason to think you are up to something that is not good. Please explain your intention FULLY so that we understand what you have in mind. Being mis-leading is not a good idea here.

Link to comment
Share on other sites

very good job rasim, Thanks dude!

but it will only work in Notepad and i want to use this function everywhere.

I can only show example. Little modified:

#include <GuiEdit.au3>

HotKeySet("^q", "_Quit")

Run("Notepad")
WinWaitActive("[Class:Notepad]")
$hWnd = WinGetHandle("[Class:Notepad]")

$hEdit = ControlGetHandle("[Class:Notepad]", "", "Edit1")

AdlibEnable("_GetText")

While 1
    Sleep(100)
WEnd

Func _GetText()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    
    Local $aString = StringSplit($iText, @CRLF, 1)
    
    Local $iLine = 0
    If $aString[0] > 0 Then $iLine = $aString[0] - 1
    
    $iLine = _GUICtrlEdit_GetLine($hEdit, $iLine)
    
    If (StringRegExp($iLine, "(?i)Line#1\z") = 1) Then _GUICtrlEdit_AppendText($hEdit, " this is just for test")
EndFunc

Func _Quit()
    AdlibDisable()
    Exit
EndFunc

:mellow:

Link to comment
Share on other sites

I can only show example. Little modified:

#include <GuiEdit.au3>

HotKeySet("^q", "_Quit")

Run("Notepad")
WinWaitActive("[Class:Notepad]")
$hWnd = WinGetHandle("[Class:Notepad]")

$hEdit = ControlGetHandle("[Class:Notepad]", "", "Edit1")

AdlibEnable("_GetText")

While 1
    Sleep(100)
WEnd

Func _GetText()
    Local $iText = _GUICtrlEdit_GetText($hEdit)
    
    Local $aString = StringSplit($iText, @CRLF, 1)
    
    Local $iLine = 0
    If $aString[0] > 0 Then $iLine = $aString[0] - 1
    
    $iLine = _GUICtrlEdit_GetLine($hEdit, $iLine)
    
    If (StringRegExp($iLine, "(?i)Line#1\z") = 1) Then _GUICtrlEdit_AppendText($hEdit, " this is just for test")
EndFunc

Func _Quit()
    AdlibDisable()
    Exit
EndFunc

:mellow:

Thanks, can you tell me how to use it in SciTE, WordPad, word (Ms Office), etc? it will work only for NotePad...
Link to comment
Share on other sites

Run("Notepad")

WinWaitActive("[Class:Notepad]")

$hWnd = WinGetHandle("[Class:Notepad]")

$hEdit = ControlGetHandle("[Class:Notepad]", "", "Edit1")

Change whats in RED to what you need. You need to be specific on the app. If you want to use any text based editor or anything that uses text, then you will need to make a list for us so we know what to code in.

Edited by Volly
Link to comment
Share on other sites

Run("Notepad")

WinWaitActive("[Class:Notepad]")

$hWnd = WinGetHandle("[Class:Notepad]")

$hEdit = ControlGetHandle("[Class:Notepad]", "", "Edit1")

Change whats in RED to what you need. You need to be specific on the app. If you want to use any text based editor or anything that uses text, then you will need to make a list for us so we know what to code in.

thanks volly, i need something which can write sentences in some places when i want them. but i can not set Hot keys for this because i will forget about the key combination and there are many sentences. like if in SciTE i want to add a comment than i will simply write ";for and the text will be changed to ";for message box."

but i want to use this function not only in SciTE but also in other all types of text editors and places.

i hope you can understand and can help in my issue. thanks once again.

[edit]also in folder renaming[/edit]

Edited by L0veUK
Link to comment
Share on other sites

The only way you can do that is through a keylogger type program. You have to log enough keys to match a phrase, a "HotString" instead of a "HotKey".

There is source all over. Have you bothered looking for any of it?

what is HotString? it's not in help file. isearched the forum but nothing exists which can match my question. please explain more i really could not understand it. Thanks.
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...