Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to change the focus back to original window via a Batch File Command  (Read 18070 times)

0 Members and 1 Guest are viewing this topic.

awhfy1

    Topic Starter


    Greenhorn

    • Experience: Experienced
    • OS: Windows 8
    Good evening, All -

    I'm new to this forum, but I love the information/assistance provided.  I've 'lurked' before - gleaning information - but I never had to post because I always found the solution.  Now, I'm stumped on something, and thought you all might be able to assist me.

    I have a very simple batch file that copies the contents of a txt file onto the clipboard.  Trust me, this is a simple file...the command is:

    C:\Windows\System32\cmd.exe /k clip < c:\transfers\test.txt
    c:\exit

    test.txt contains the information that I want pasted to the clipboard (e.g. my email address).

    Next, I've assigned a hotkey to the shortcut that runs that batch file.  So, for example, CTRL+ALT+O would copy the text in test.txt onto the clipboard.  I can then use CTRL+V to paste that pretty much anywhere.

    So far, so good.

    Now, let's say that I'm on a webpage, and it asks for my email address.  Rather than typing it, I press CTRL+ALT+O to place it on the clipboard.  Here's where I hit my issue.  When the batch file runs, I lose the focus on the field that I wanted to fill in on the webform (or whatever program), so I have to click back to the field and THEN paste.

    Here is my question...is there a way that I can adjust the batch file so that it will "hold" or "return to" the field where I hit the hotkey combination, so that all I need to do is hit CTRL+V (or, better yet, where it would "know" to paste right there and I could save the CTRL+V step)?

    In other words, I want the focus to STAY WHERE IT WAS or to RETURN TO WHERE I HAD IT.  The general concept is to SAVE keystrokes, and having to get the focus back adds some extra steps.  Not the end of the world, but still, I'm trying to make the process better!

    Thank you, in advance, for any insight/knowledge you may have.  I've given a very simple example above, but if I can solve the focus issue, I can think of lots of places to use this simple command sequence.

    Have a great night!

    NOTE:  The batch file above works on Windows 7 or 8 or 8.1

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Your objective is not clear.
    There are some  here that can do anything with a batch file,
    - except make good coffee.  ;D
    But seriously, for sometime Microsoft has recommended  people to lo use some kind of Windows Script Host pt for tasks that involve the windows graphical  interface. Batch commands are butter used for things that stay at the condom line.




    awhfy1

      Topic Starter


      Greenhorn

      • Experience: Experienced
      • OS: Windows 8
      I'm just trying to create a simple solution (fairly low-tech) to solve an issue that someone in my office raised - the ability to copy/paste some 'set text' (whatever they want, I used an email address as the example) using a hotkey combination into some field.  That's all.  Nothing complicated...just a tool for 'mere mortals' to use to simplify their lives (if they want).

      Thank you for your thoughts.

      I'm ashamed to say that I don't know what 'Windows Script Host pt' is (although I can probably find out elsewhere on this forum!)

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      It was not my intent to turn you away from Batch files. Really, the WSH can be part of a batch file.
      Here is an article about how Microsoft introduced Windows Script Host many years ago, The goal was to extend the power of batch to include some syntax from other kinds of tools.
      http://en.wikipedia.org/wiki/Windows_Script_Host
      Quote
      ...WSH engines include various implementations for the REXX, BASIC, Perl, Ruby, Tcl, PHP, JavaScript, Delphi, Python, XSLT, and other languages.
      Windows Script Host is distributed and installed by default on Windows 98 and later versions of Windows. It is also installed if Internet Explorer 5 (or a later version) is installed. Beginning with Windows 2000, the Windows Script Host became available for use with user login scripts. ...
      On this forum the preference seems to be using VbScript with batch to go into some things that would  need more control.  Such as forms.
      One advantage of WSH is, let's say,  somebody in you group might be more handy with Python. He could write some good code and it can be started in batch.  Then the batch might chge some detail and finish the job.

      Back to VBS, VBScript:

      Using VBScript to Fill Out a Web Form

      Is that he kind of thing you want?  More examples are available.  :)

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      If you want the easy route for this, if the text is always in the same location on the display, I'd go with creating a Keyboard/Mouse macro with a tool like Jitbits Macro Creator. I bought this software years ago and use it for making a stand alone exe to run on other systems or same system. * To work on other systems, display resolution has to be the same and placement of trigger point ( desktop icons etc ) have to match up for exact X,Y location. A macro to complete this could be made in as little as 3 minutes. Thats why I like it so much is because otherwise your spending hours writing code and debugging to get it right. This tool you can just say start recording the process. And then every movement, mouse click, and keyboard action is recorded in realtime until you select to end the recording. You can then play it back and it will perform exactly what you did. You can then either compile it into an EXE to share with other systems, or you can go in and look at the macro instruction list and edit it to change time delays to make it run faster if you want it to get to an icon and point and click to trigger it faster than your initial recorded motion of your hand to mouse etc, as well as you can add a loop instruction in it with a counter if you want to get advanced and customize it to run X-many times, or infinite loop to run non stop until an abort key is entered ending the macro.

      This program was some of the best spent money of programs I have readily available to me: https://www.jitbit.com/macro-recorder/

      awhfy1

        Topic Starter


        Greenhorn

        • Experience: Experienced
        • OS: Windows 8
        Thank you Geek After Dark!  I'll check out the links/info.  We don't have an internal IT department...I'm as close as it gets, and I'm just not afraid to try things...but I am NOT a programmer.  I AM a good 'monkey'...meaning I can take/adjust existing things to suit our needs  ;).  Not necessarily the 'cleanest' or 'prettiest', but usually (with luck) functional.  So, I try to go with fairly 'low tech' solutions, so others can copy/adjust as needed without much tech knowledge.  In other words, if I can document with images/text, then perhaps someone else can do it, as well.  I appreciate your ideas!

        awhfy1

          Topic Starter


          Greenhorn

          • Experience: Experienced
          • OS: Windows 8
          Thank you, Dave Lembke.  The location of the text is NOT always in the same spot on the screen, so I don't think that this will work for this situation, but it is DEFINITELY an interesting little piece of software and one that I will ABSOLUTELY check out (but for other challenges).  I LOVE the idea of quickly scripting keystrokes and have needed this tool often, so I'm sure that I'll need it again!  I'm still trying to solve THIS issue, but now I know that I have a solution for some other issues!

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          As DaveLembke said ,  a macro keystroke recorder might help in some cases.
          Some other things for future reference.
          There are a number of ways surrogate programs will  imitate the typing of a real person. This is useful of applications that only take input from the keyboard.
          For more on this idea see:
          Auto Hotkey,
          Keyboard shortcut,
          Macro,
          Modifier key,
          Shortcut key.

          Or look here:

          10 AutoHotkey Alternatives To Create Your Own Macros and ...


          And there is more... but this is enough for now.  :)

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          would it not work to have the launched command prompt start minimized?


          start "" /MIN "cmd.exe /c clip < c:\transfers\test.txt"


          I also don't think the /k switch makes sense for your usage- I swapped it for /c here.
          I was trying to dereference Null Pointers before it was cool.

          awhfy1

            Topic Starter


            Greenhorn

            • Experience: Experienced
            • OS: Windows 8
            Thank you, Geek!  I'll check those out.

            BC_Programmer...thanks for the idea (not sure what switch does what, so I tried your version), but it makes no difference...identical behavior.  I end up on the same page/form/window, but the focus is lost.  You have to click to return the focus and do the paste.

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Still not certain of the objective.
            How to Automatically Fill in Repetitive Web Forms
            Is a topic in Google search. Also called Autofill. Both Chrome and Firefox can do this.
             Here is one of many finds in a search.
            http://www.makeuseof.com/tag/kill-the-tedium-of-online-forms-with-these-10-great-autofill-tools/
            Quote
            What Does It Mean To “Autofill” Online Forms?
            It simply means that a program of some kind automatically detects the presence of a form on a webpage and fills in the information you have previously given it. It is important to use a program and service which is reputable as your information can be sensitive. Of course, it is up to you what you give it, but obviously the more information you provide, the more it can fill in for you.

            Your original topic was about keyboard focus. I think that has to be done at a different level, like maybe in C# or some other tool like that.
            https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.focus%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
            The above does not seem to apply to a batch file.  :)

            awhfy1

              Topic Starter


              Greenhorn

              • Experience: Experienced
              • OS: Windows 8
              Thanks, Geek!  I appreciate it. 

              My original idea of the web form as an example was a bad one because you are right, autofill exists...and I'm not looking to use this feature for that.  I was just trying to find a very simply example (and I chose wrong).  The issue is all about keyboard focus...thanks for the thoughts on C#...if we have to go to that level, we'll probably just have to click to regain the focus :).  None of us are "real" programmers!

              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              A number of articles on 'keyboard focus' can be found. These almost use sopme language other than pure batch. Batch, be default, steals keyboard focus unless it cam run in the background.
              Here is how I work. I have a whole  lot of words and phrases that I can use to write e-mail, fill in forms, remember passwords and do almost anything that is repetitive,. I have to. Whit my vision problem I can not see the print on the screen, unless Iuse the magnifier, which is awkward.
              Here is how it works. I get to a document, e-mail, web form or whatever where the keyboard focus is on a field. I already know what it is from prior use. So I hit control 1 and a little windows pops up and gives me a choice of 26 items, labeled A -Z. If what I want is  not in that lost, I can go to another list until I find what I need.  When I find what I want, I just press a single key and the keyboard focus goes back to where is was and the phrase I needed is slowly typed into the flied.  This can even include the TAB key to advance to the next field.
              But I did not write the program. This is a form of 'keyboard  automation' and uses a very simple script that most can understand.
              So I did not have to do anything about keyboard focus. The program does that by itself. But it is not a batch program. It is what at one time was can a TSR,a background task that monitors the keyboard for hot-keys and responds to commands in a script.
              In short, it is a kind of 'Hot Key'  tool that does almost anything a user would do at the keyboard. It remembers where the cursor was and comes back there to do its job after you start a preset action.
              Put another way, the cursor position has to be remembered before anything else.  So it should be part of the hot key  thing.
              Let me know if this is anything like you want.
              I would imagine that there might h be some way to preserve the keyboard focus in a batch file, but I don't  know how.



              awhfy1

                Topic Starter


                Greenhorn

                • Experience: Experienced
                • OS: Windows 8
                THANK YOU, Geek!!!  That's terrific information (and you're confirming what I'm figuring out through my research).  Yes, we may have to go that direction.  I truly appreciate all your information and guidance.  I know just enough to be dangerous  ;D

                Geek-9pm


                  Mastermind
                • Geek After Dark
                • Thanked: 1026
                  • Gekk9pm bnlog
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 10
                OK, now we will be on the lookout , now we know you are dangerous.
                The tool I use is called KetText and I paid for it to get all the features.'
                Here is the documentation.
                http://www.mjmsoft.com/ktext.pdf
                I recommend reading the manual before trying.  :)