Jump to content

Send() in inactive window


Recommended Posts

I was wondering if there was a library or something which provides the capability to Send() to inactive windows, and I know what you're thinking, I could just use ControlSend(); the reason I can't use that in this situation is because I need to hold down keys for specific prolonged periods of time. Also activating the window, Send()ing then de-activating the window isn't really an option here, I need the target window to always be in the background. I've looked around the forums for an adequate amount of time and didn't find anything useful, perhaps because the threads were all 10 years old, nevertheless, if anyone has any suggestions they would be greatly appreciated.

Thanks!

Link to comment
Share on other sites

Hey hello there,

Let's try to give you a chance to get answers, first of all please read My signature: "How to ask help", 

 

We need more information to help you, 

Can you please provide us the goal of your script what are you trying to accomplish exactly ?

Why you cannot send that command in a focused windows ? 

What application are you trying to automate ?

 

What have you tryed so far ? 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

You could use _WinAPI_PostMessage() and send WM_KEYDOWN to hold the key down, sleep some time and WM_KEYUP to release it.

#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

$hWnd = WinGetHandle("Your window")
$iVkCode = 0x45 ; A key, see https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes

_WinAPI_PostMessage($hWnd, $WM_KEYDOWN, $iVkCode, 0)
Sleep(100)
_WinAPI_PostMessage($hWnd, $WM_KEYUP, $iVkCode, 0)

However, please note that handling such messages is up to the receiving window. Some developers code their message receiving routine in such way that it only processes messages if their window is in foreground (active and in focus). Changing such behaviour is probably not possible with AutoIt, since you'd have to do some reversing on the application in order to hook and rewrite their message loop (and you would have to create a DLL for that).

Additionally, Windows includes an additional LLKHF_INJECTED flag in keystrokes sent by other applications, if it's not a keyboard driver. Thus, an application can find out whether a keystroke came from the user's keyboard or it was simulated by another application (and block these inputs) simply by setting a low level keyboard hook and checking for that flag. In this case, you would have to develop a driver.

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

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

×
×
  • Create New...