none
Grabbing Text from a File then Outputing that text. RRS feed

  • Question

  • Hello All!

    I researched the following code.. but i'm stumped about moving further with my project.

    I'm trying to make a script that reads a .txt file, grab text between " " quotes, then typing that text out in addition to SendKey {Enter] (to make another paragraph) Sendkey / (the divide sign?) then another {Enter} for another paragraph

    Const ForReading = 1
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\Users\Philip\Dropbox\IFTTT\Twitter\Text.txt, ForReading)
    
    Do Until objFile.AtEndOfStream
        strText = ""
        strCharacter = objFile.Read(1)
        If strCharacter = Chr(34) Then
            Do Until objFile.AtEndOfStream
               strNewCharacter = objFile.Read(1)
               If strNewCharacter = Chr(34) Then
                   Exit Do
               End If
               If strNewCharacter <> "" Then
                   strText = strText & strNewCharacter
               End If
            Loop
            Wscript.Echo strText
        End If
    Loop

    To my understanding, the above script grabs every text between " " quotes within the .txt file. Once it grabs the texts between " " quotes, I want the program to then do the following. 

    Sendkeys {ENTER}, //press the enter key

    Sendkeys {NUMPADDIV} //press the / key

    (type the items inside the " " quotes) //types out texts between the " " quotes

    Example:

    Text file contains: #grocerylist "groceries are" "eggs.12" "bacon.5"

    Assuming a text file is open, the computer will type out the following

    (Enter) //a new line

    /groceries are eggs.12 bacon.5

    (Enter) //a new line

    I hope that makes sense! Not sure how to collaborate the above inquiries into a single script :(

    • Moved by Bill_Stewart Wednesday, September 9, 2015 7:45 PM User should not be doing this
    Monday, August 3, 2015 3:50 AM

Answers

  • I thought "sendkeys, {Enter}" would mean that I was telling my keyboard to press enter.

    Yes. But this depends on which window has the focus, and the addition of integrity levels between running processes can also interfere with what you might expect.

    Use the search box at the top of this forum and search for the term sendkeys.

    You will find a large number of threads that say, "sendkeys is not reliable. Do not use it."


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Thursday, August 20, 2015 9:12 PM
    • Marked as answer by Bill_Stewart Wednesday, September 9, 2015 7:44 PM
    Monday, August 3, 2015 4:32 PM

All replies

  • What is between quotes and why. What is in the file?

    You have not provided enough information and wht you have posted is very vague.


    \_(ツ)_/

    Monday, August 3, 2015 4:22 AM
  • Also note that many home users, gamers and hackers come her with questions about "SendKeys".  YOu need to understand that SendKeys is very unreliable in modern Windows and will not likely work as you require.  Using it wit IE will fail intermittently.


    \_(ツ)_/

    Monday, August 3, 2015 4:24 AM
  • Thanks for the replies.

    Like the example above, what's going to be inbetween these quotes are letters, a period, and numbers.

    In regards to sendkeys, I don't know the proper language to tell my keyboard to press enter, forward slash, etc. I thought "sendkeys, {Enter}" would mean that I was telling my keyboard to press enter.

    Disregarding the "Grocery list" example above, this script is for a videogame that has little to no ways to regulate bad players in a Custom Arena Match (part of the game). I'm trying to better people's well beings and overall gaming experiences.

    I'm using IFTTT + Dropbox. When ever somebody sends a Tweet to: @Username #kick "Player1.1234" then IFTTT will grap the Tweet, create a .txt file and place it in my Dropbox. This script will then check my Dropbox for this specific file name every 5s. When it sees the file, it will grab the text between the " " quotes (in this case, Player1.1234) then immediately execute the command to /kick player1.1234 because Player1 was being roudy and ruining other people's gaming experiences. 

    Note: The player issuing the kicking already has moderator privileges. I'm trying to make it so that I don't have to be on 24/7. Instead, I can just Tweet the above items when my friends sends me a text to kick a certain player. If i'm at work, I can send out a Tweet called: @Username #kick "playerx.xxxx" and my computer should execute the file.


    • Edited by Pregjo Monday, August 3, 2015 4:30 PM
    Monday, August 3, 2015 4:22 PM
  • I thought "sendkeys, {Enter}" would mean that I was telling my keyboard to press enter.

    Yes. But this depends on which window has the focus, and the addition of integrity levels between running processes can also interfere with what you might expect.

    Use the search box at the top of this forum and search for the term sendkeys.

    You will find a large number of threads that say, "sendkeys is not reliable. Do not use it."


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Thursday, August 20, 2015 9:12 PM
    • Marked as answer by Bill_Stewart Wednesday, September 9, 2015 7:44 PM
    Monday, August 3, 2015 4:32 PM
  • You will not be able to do this with SendKeys.

    Twitter has an API. Use the Twitter API to get the messages in usable form.


    \_(ツ)_/


    • Edited by jrv Monday, August 3, 2015 4:33 PM
    Monday, August 3, 2015 4:32 PM
  • Note that Twitter, to prevent spam, obfuscates the interface just so SendKeys will not work consistently.


    \_(ツ)_/

    Monday, August 3, 2015 4:37 PM
  • Oh, I understand now.

    Sendkeys sends to the active window so If i'm multitasking or switching to different windows then it's not going to work effectively.

    Even if my Game window is open 100% of the time, Sendkeys could still "send keys" to another window, correct?

    My game window should be the only thing up at any time while other windows are minimized. There aren't any other specific text fields in my active game window. Do you still think sendkeys will still be problematic? I'm definitely looking for other alternatives to output text on a screen without directly modifying game memory lol.

    In regards to Twitter Spam, I sent out 9 "@Username #kick" Tweets and Four entered my Dropbox immediately as text files. The other 5 showed up a couple minutes later but I still received them as text files... eventually. I believe there's a 1,000 Tweet limit per day so there's no way i'll reach this spam threshold. It's a matter of when my Dropbox receives these Twitter text files - it usually takes a minute or two which is acceptable at the moment.

    Monday, August 3, 2015 5:33 PM
  • Assuming all of this works...what is the problem?  YOu have a file displayed on the screen.  How are you going to search that? YOu cannot do it with SendKeys.

    Use the Twitter API.  You will be able to read your received tweets directly as text.

    If you want to extract text from a file then read the file a line at a time and use a RegEx to extract the parts you need..

    Part of the problem is that you are not asking a clear question.  I suspect what you are trying to ask is "How do I extract text from a file based on a pattern?"

    Post an example of the file.


    \_(ツ)_/


    • Edited by jrv Monday, August 3, 2015 5:39 PM
    Monday, August 3, 2015 5:36 PM
  • Textfile contents:

    @TweetUser : @TweetUser #kick "player1.1234" Via Twitter http://twitter.com/TweetUser/status/628251552952
    August 03, 2015 at 12:10PM

    Code grabs the text: "player1.1234"

    Assuming the correct window is open.. I want the program to

    objShell.SendKeys "{ENTER}" //press the Enter key

    Wscript.Sleep 100

    objShell.SendKeys "Chr(181)" //press the Divide key

    Wscript.Sleep 100

    objShell.SendKeys "kick" //type out "kick"

    Wscript.Sleep 100

    objShell.SendKeys " " //inserts a space after "kick"

    output player1.1234 //I lack code for this. Can I call strText?

    objShell.SendKeys "{ENTER}" //finish with another Enter key input

    /kick player1.1234

    I don't have finished code yet. I was going to configure that original code that I posted at the very top, in order to grant multiple kick functionalities but that definitely doesn't have to happen. It can be as simple as reading a file and grabbing text between " " quotes rather than a loop that searches for multiple " "


    • Edited by Pregjo Monday, August 3, 2015 7:42 PM
    Monday, August 3, 2015 7:40 PM
  • As I posted.  I do not care about the "SendKeys".  You want to get a string from a file.  Is that correct?

    @TweetUser : @TweetUser #kick "player1.1234" Via Twitter http://twitter.com/TweetUser/status/628251552952

    Here is the Regx pattern to get the stuff in quotes: """(?<x>.*)"""


    \_(ツ)_/

    Monday, August 3, 2015 7:51 PM
  • Here is an article with examples: http://www.regular-expressions.info/vbscriptexample.html


    \_(ツ)_/

    Monday, August 3, 2015 7:52 PM