Jump to content

Recommended Posts

Posted

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!

Posted (edited)

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

  Reveal hidden contents

 

Posted

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

  Reveal hidden contents

 

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
×
×
  • Create New...