Sign in to follow this  
Followers 0
Stooney

Send input to inactive window?

22 posts in this topic

Say I have Window1 and Window2 and Window1 is active. Is it possible to send keyboard input to Window2 without losing focus on Window1? Basically Window1 must stay active the entire time.

Share this post


Link to post
Share on other sites



Hi Stooney,

1st Welcome to the AutoIt Forums! :idiot:

Some of the following tips may not apply to you, but it may make your life a bit easier here on the forum in the future.

CODE
  • Did you know that we have an awesome search feature?

    You can find many answers to your current questions, just by typing in the right search patterns.

  • A suggestion is to use the Advanced Search mode:

  • Type your specific search term in quotes.
  • Click the forum you want to search in (the one most likely to have your information would generally be the Example Script forum and or the General Help and Support Forum).
  • Click on "Search titles only" radio button.
  • Click perform search.
The above will help you narrow down your searches and prevent you from unneccesarily posting a new thread.

[*]Also, you should try to read the Sticky posts that are at the top of each of the AutoIt Forums you enter such as:

[*]Forum Etiquette:

  • Making a new thread:

    • Use the Search feature first to see if your question has already been answered.
    • Look in the help file as well before even thinking of posting (When what you want could be obtained by simply reading the help file, you don't generally get a good response from your AutoIt community).
    • Titles are very important here. 1 word titles or titles like "help me", "write something for me", "I'm a noob" etc... aren't tolerated.
    • Use common sense when creating a new thread.

      Ask yourself if the title is descriptive enough to even interest someone (preferably those that know what they are talking about) to even look at your thread, let alone reply in it.

    • Think about how it would show in the search feature if someone were to look for something just like you are looking for (think of the keywords you used yourself and obviously didn't find anything (because we know you used the search feature :) ) and use those types of keywords in your title as well).
  • Thread content:

    • Be descriptive with your query. (Make sure we actually know what you want to do).
    • Show you've made an effort in coding what you want (provide the reproducer code (generally no more than 50 lines as people lose interest in debugging someones script for free)).
    • Don't talk in ebonics. A lot of the forum members are adults, and a lot of them know how to help you, but talk like a child, you'll be treated as such.
    • Don't ask for help making keyloggers, spam (even if it's to do as a prank), or anything that can be thought of as malicious. You'll more than likely have the thread locked by a moderator, and take a bashing from your fellow AutoIt community.
    • When posting code, use code boxes. This can be accomplished by using [code ]<content here>[/code ] (No spaces between the brackets []).

      Using code boxes will keep the indentation and make it easier to read for others to help you.

  • Bumping your threads:

    • Use common courtesy here.

      Keep in mind every time you bump your thread to the top of the forum, you knock the other threads down a notch.

      Everyone posting for help has just as much right for their threads to get read as you do.

      Because of that, do not bump your post more than once in a 24 hour period.

      A Bump is simply posting in your thread with nothing that pertains to your query with the sole purpose of moving it up.

      Deleting previous bumps, and posting new ones is not tolerated, and the moderators can find those deletions, so do yourself a favor and don't cross that line >_< .

  • Rude or obnoxious content:

    This falls pretty much under the common sense thing. If you use it (common sense) before posting, you won't have issues.

    • Don't use foul language, remember, a lot of the community is at work when they read these threads.
    • Don't provoke or instigate an argument with someone.
  • Double Posting:

    • It's understood that sometimes there's a lag in the system, and sometimes people don't see their post go up right aways so they post again.

      If this happens to you, simply notify a moderator with the report feature in the post, and politely ask them to delete it.

    • If you're just creating another topic because your original topic is not being answered the way you want or at all, this is not tolerated. You could lose your posting privileges all together over it.
  • Non-English languages

    • If English is not your primary language, please make an attempt to interpret (yourself or online) and post that interpretation.

      We have wonderful users from around the world, so after you've done your post in English, back it up with your question also in your native tongue (You may find your answer much quicker using both).

That's it for now, I hope you have a wonderful learning experience, and hope to see you contribute to the community as your knowledge grows.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Say I have Window1 and Window2 and Window1 is active. Is it possible to send keyboard input to Window2 without losing focus on Window1? Basically Window1 must stay active the entire time.

I do not think you can do this directly but you can do that:

AutoItSetOption("WinTitleMatchMode",2)
$GUI = GUICreate("GUI",100,100)
$BUTTON = GUICtrlCreateButton("SEND",20,20,60,60)
GUISetState(@SW_SHOW,$GUI)

While 1
    $MSG = GUIGetMsg()
    If $MSG = $BUTTON Then
        Run("notepad")
        WinWait("Notepad")
        WinSetState("Notepad","",@SW_MAXIMIZE)
        WinActivate("GUI")
        TrayTip("Look in Notepad","I write text without lose focus",1)
        Sleep(3000)
        ControlSend("Notepad","","[CLASS:Edit;INSTANCE:1]","Text")
    ElseIf $MSG = -3 Then
        Exit
    EndIf
    Sleep(15)
WEnd
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Thanks for your response Adreik. How does ControlSend work exactly? The example you gave me does everything but send "Text" to the notepad document. It opens notepad, maxmizes it, activates the gui window then stops. No text makes it to notepad.

Share this post


Link to post
Share on other sites

Thanks for your response Adreik. How does ControlSend work exactly? The example you gave me does everything but send "Text" to the notepad document. It opens notepad, maxmizes it, activates the gui window then stops. No text makes it to notepad.

That's because the title to notepad is incorrect.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks for your response Adreik. How does ControlSend work exactly? The example you gave me does everything but send "Text" to the notepad document. It opens notepad, maxmizes it, activates the gui window then stops. No text makes it to notepad.

ControlSend() sends a string of characters to a control in this case send "text" to Edit1 from Notepad.

You need to stay 3 sec and then text is send to Edit1 (Spleep(3000)).

That's because the title to notepad is incorrect.

What is wrong in title?

The script work fine for me.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

ControlSend() sends a string of characters to a control in this case send "text" to Edit1 from Notepad.

You need to stay 3 sec and then text is send to Edit1 (Spleep(3000)).

What is wrong in title?

My notepad titles are "Untitled - Notepad", you'd be better off using "[CLASS:Notepad]"

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

When notepad is open the title is 'Untitled - Notepad'. I've tried that and 'Notepad' to no avail. Am I missing something?

(I'm a php coder, autoit syntax looks like greek to me)

Share this post


Link to post
Share on other sites

When notepad is open the title is 'Untitled - Notepad'. I've tried that and 'Notepad' to no avail. Am I missing something?

(I'm a php coder, autoit syntax looks like greek to me)

I use option "WinTitleMatchMode" to match any substring in the title.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Would vista cause this type of problem? That's what I'm using.

Share this post


Link to post
Share on other sites

Remove from script, this line:

Sleep(3000)

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Just tested on an XP machine and it works fine. Any idea what tweaks are needed to make it work on Vista Ultimate 64-bit?

Share this post


Link to post
Share on other sites

Just tested on an XP machine and it works fine. Any idea what tweaks are needed to make it work on Vista Ultimate 64-bit?

Change ControlSend function with ControlSetText, maybe will work on Vista.

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Just tested on an XP machine and it works fine. Any idea what tweaks are needed to make it work on Vista Ultimate 64-bit?

Use the AutoInfo tool to get the vista control id/classnamenn and the class of the parent notepad window.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Class: Notepad

Control ID: 15

Classnamenn: edit1

Share this post


Link to post
Share on other sites

Class: Notepad

Control ID: 15

Classnamenn: edit1

I can't fire up my Vista box at the moment ... it is a curious issue though.

I know that vista has a thumbnail gui as well that I "believe" has the same info as the regular gui windows. I thought that Jon fixed that a long time ago, but now you have me curious if it is sending to that thumbnail GUI.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Anything I can do to help in the meantime? There is no rush on this as it's just a side project.

Share this post


Link to post
Share on other sites

Anything I can do to help in the meantime? There is no rush on this as it's just a side project.

Instead of Edit1, try sending to the handle of the control. In autoinfo you can see Handle down under the control info. And instead of using class anything or titles, use the Handle for the Notepad as well (also found with autoinfo above the control info).

Example:

Global $h_wnd = HWND(0x4099300)
Global $h_edit = HWND(0x39C003)
ControlSend($h_wnd, "", $h_edit, "Some Text")
Let us know if that sends the data. (HWND() Is necessary)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I don't see any handles, here's what I get:

Press CTRL-ALT-F to pause the display.

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: Untitled - Notepad

Class: Notepad

Size: X: -4 Y: 24 W: 1065 H: 662

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 673 Y: 518

Cursor ID: 5

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xC0C0C0 Dec: 12632256

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 0 Y: 0 W: 1057 H: 616

Control ID: 15

ClassNameNN: Edit1

Text:

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

(1):

(2): Ln 1, Col 1

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

Share this post


Link to post
Share on other sites

Ok, I just installed the latest autoit (lol) and now I see handles. Which is which though?

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