Jump to content

adding to text document


tsolrm
 Share

Recommended Posts

Hi all

I need some guidance please how to do the following:

Add the selected text into the text document when a certain button is pressed

For example

Posted Image

"Topic Title" is selected with a mouse. I want those words to appear in the text document (which is in the same folder as the script) when I press "+"

Is this possible at all? If not then are there any other options?

Thanks

Link to comment
Share on other sites

Welcome to the forums.

Many things can be done but that little picture doesn't really give us any insight into the code you have tried nor have you been overly descriptive as to what you are trying to do. Please provide us with more details and code that you have attempted.

Also: Please wait at least 24 hours before bumping your posts.

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 don't know how I can make this sound clearer.

There is a text document in the same folder as the script.

When I select something with my mouse (as shown on the screen shot) and press a certain button - I want the selected stuff to be written into the text document.

For example I run the script (it's in the tray) I go to a website (for example http://news.bbc.co.uk/) and select a few words and then press a button and I want the selected bit to be copied into the text document.

Link to comment
Share on other sites

I don't know how I can make this sound clearer.

There is a text document in the same folder as the script.

When I select something with my mouse (as shown on the screen shot) and press a certain button - I want the selected stuff to be written into the text document.

For example I run the script (it's in the tray) I go to a website (for example http://news.bbc.co.uk/) and select a few words and then press a button and I want the selected bit to be copied into the text document.

That's pretty much clear, but since GEOSoft also asked for code you tried it would be smart thing to post it. That way you could be pointed to your mistakes and you could learn much from that.

What you ask is trivial to code. But then again, this is not 'Order code' forum.

That's the point of the post you were referring to.

Link to comment
Share on other sites

I would suggest you start by learning how to do the following:

1. Run a function if a key is pressed. Hint: HotKeySet()

2. Append text to a file

3. Combine the above 2

Post your code when your done or if you have issues. Everything you need is in the help file.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

That's pretty much clear, but since GEOSoft also asked for code you tried it would be smart thing to post it. That way you could be pointed to your mistakes and you could learn much from that.

What you ask is trivial to code. But then again, this is not 'Order code' forum.

That's the point of the post you were referring to.

I can not write the code because I have no idea how to do this. I wouldn't be asking for help then would I?

And stop sending people to read the help file. I know what the HotKeySet() but I DO NOT KNOW THE WAY how to make the selected text go into the text document.

HotKeySet("!1", "AddName")

Func AddName()

$file1=FileOpen("nicknames.txt", 1)

FileWriteLine($file1, $SelectedText & @CR)

FileClose($file1)

EndFunc

the question is how do assign what I've selected with the mouse to $SelectedText

Edited by tsolrm
Link to comment
Share on other sites

How about a simple

HotKeySet("{+}", "_AddText")
While 1 * Sleep(10)
WEnd

Func _AddText()
$oldClip = ClipGet()
Send("^{c}")
FileWriteLine("nicknames.txt", ClipGet() & @CRLF)
ClipPut($oldClip)
EndFunc
Link to comment
Share on other sites

$file=FileOpen("BanList.txt", 1)

HotKeySet("{+}", "AddText")

While 1 * Sleep(10)

WEnd

Func AddText()

$SelectedText = ClipGet()

Send("^{c}")

FileWriteLine("BanList.txt", $SelectedText & @CRLF)

ClipPut($SelectedText)

EndFunc

FileClose($file)

It doesn't work

I've tried Send("^c") too, but it doesn't copy the selected text into the clipboard

Edited by tsolrm
Link to comment
Share on other sites

HotKeySet("{+}", "_AddText")
HotKeySet("{NUMPADADD}", "_AddText")
HotKeySet("{ESC}", "_Quit")

$hFile = FileOpen("BanList.txt", 1)

While 1
    Sleep(20) ; Idle around and keep alive
WEnd

Func _AddText()
    $OldClip = ClipGet() ; Save previous clipboard content
    
    Send("^c")
    $SelectedText = ClipGet()

    FileWriteLine($hFile, $SelectedText) ; @CRLF is automatically added
    
    ClipPut($OldClip) ; Restore previous clipboard content
EndFunc

Func _Quit()
    FileClose($hFile)
    Exit
EndFunc

Link to comment
Share on other sites

I copied and pasted the code that you gave me and it does not work.

Sleep(5000)

ClipPut ("")

Send("^c")

$SelectedText = ClipGet()

$file=FileOpen("BanList.txt", 1)

FileWriteLine("BanList.txt", $SelectedText & @CRLF)

FileClose($file)

This works. But when I try using a function - the text document remains unchanged.

Edited by tsolrm
Link to comment
Share on other sites

Read the HotKeySet function description (and references) carefully. {+} is for shift + = which produces +,

I've spent like 20 minutes trying to figure out what's wrong and the answer was so obvious ;) Anyway thanks for help everyone.

Link to comment
Share on other sites

Could you also help me please with this:

Func Ban()

$hFile=FileOpen("BanList.txt", 0)

WinActivate("text.txt")

While 1

$BanLine = FileReadLine($hFile)

If @error = -1 Then ExitLoop

MsgBox(0, "Line read:", $BanLine)

Send ($BanLine)

Send ("{ENTER}")

Wend

EndFunc

I'm trying to read line by line from the text document and then Send this into another document.

Without the Send ($BanLine)

Send ("{ENTER}") it works fine but as soon as I add this - it crashes

Link to comment
Share on other sites

Func Ban()
    $hFile=FileOpen("BanList.txt", 0)
    $sText = FileRead($hFile)
    FileClose($hFile)
    WinActivate("text.txt")
    
    $aLines = StringSplit(StringStripCR($sText), @LF)
    If @error = 0 Then
        For $i = 1 To $aLines[0]
            Send($aLines[$i], 1)
            Send("{ENTER}")
        Next
    EndIf
EndFunc

Link to comment
Share on other sites

Thank you but this doesn't quite work

I have

HotKeySet("{1}", "AddText15")

HotKeySet("{2}", "AddText20")

HotKeySet("{3}", "AddText30")

HotKeySet("{4}", "AddText40")

So when the text from the banlist contains /ban NaTuRe^BoY 15

The "1" calls out the function

Func AddText15()

Send("^c")

$SelectedText = ClipGet()

$Replace=""

$SelectedText=StringReplace($SelectedText, ' ',$Replace)

$hFile = FileOpen("BanList.txt", 1)

FileWriteLine($hFile, "/ban "&$SelectedText&" 15")

FileClose($hFile)

EndFunc

And the banlist content gets changed. Anyway around this?

Edited by tsolrm
Link to comment
Share on other sites

I really advise you to take your time when somebody gives you a solution and try to understand the code; jumping so quick to the conclusion "it doesn't work" won't lead to anything but anoying the people who are trying to help you. Also, be aware about what your code does; do not throw together scrapped lines of code and wonder why it doesn't work.

And the banlist content gets changed. Anyway around this?

... what do you think FileWriteLine($hFile, "/ban "&$SelectedText&" 15") does ???

Send ("{ENTER}") it works fine but as soon as I add this - it crashes

Think about what characters (other than letters and digits) are usually used in these nicknames; once you figure that, read about Send function and how "special characters" are handled.

Hint: "flag" parameter.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Think about what characters (other than letters and digits) are usually used in these nicknames; once you figure that, read about Send function and how "special characters" are handled.

flag [optional] Changes how "keys" is processed:

flag = 0 (default), Text contains special characters like + and ! to indicate SHIFT and ALT key-presses.

flag = 1, keys are sent raw.

Func Ban()
    $hFile=FileOpen("BanList.txt", 0)
    $sText = FileRead($hFile)
    FileClose($hFile)
    WinActivate("text.txt")
    MouseClick("Left", 76, 645, 3)
    $aLines = StringSplit(StringStripCR($sText), @LF)
    If @error = 0 Then
        For $i = 1 To $aLines[0]
            MouseClick("Left", 76, 645, 3)
            Send($aLines[$i], 1)
            Send("{ENTER}")
        Next
    EndIf
    MsgBox(0, "Banned", "All the users have been banned")
EndFunc

The code already contains the flag "1"

Send($aLines[$i], 1)

It doesn't matter, the numbers still call out the functions.

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