Jump to content

Recommended Posts

Posted (edited)

I am looking for a way to interact with a window while maintaining its @SW_SHOWNOACTIVATE integrity. I am building a mini suite with handy tools and I essentially want to be able to 'Select' a window that will be forced into out of focus mode, yet can still be interacted with. Think of the Windows 10 feature: "Scroll inactive windows when I hover over them". I found a nifty script in the forums that allows for a window to never gain focus and it works for buttons, resizing, moving, but does not allow input... How would I allow input when 'Hovering' over the window for example? Or possibly once a window is 'Set' into this mode, all input is under ControlSend()? (Just trying to throw my train of thought out there, I know that has many limitations in this case.)

EDIT: What I mean by ControlSend limitations is I think for dynamic input I would have to assign each key to call a function to ControlSend that key pressed to the window? Since the goal is to send any and all input to that window itself, and not a static string.

Global Const $WS_EX_NOACTIVATE = 0x08000000

$MyGUI = GUICreate("Test", 500, 500, -1, -1, -1, $WS_EX_NOACTIVATE)
$input = GUICtrlCreateInput("", 200, 200)

GUICtrlSetState(@SW_SHOWNOACTIVATE, $MyGUI)

GUISetState()

While 1
   Switch GUIGetMsg()
      Case -3
         Exit
   EndSwitch
WEnd

 

Edited by kjpolker
elaborated
Posted
13 hours ago, 636C65616E said:

Maybe directly Post/Send Message ?

Could you please explain more of what you mean? I'm not sure what options there are available. Or are you you suggesting I go with sending the keystrokes to the window handle directly (ControlSend)? I figured there could be another creative way since Windows 10 can interact with other windows by just hovering over them (never focusing).

Posted (edited)

The mechanism behind the magic of Send and ControlSend and anyway nearly any interaction with a window is based on a simple concept called the Window Message that handle all Window interactions (yeah fetching a Window Title need to use this mechanism for instance)

I will show you a quick example to be more clear. But here some readings:

EDIT: if you just want to 'communicate' with the window by your own, and not neceserraly use stuff the window handle initially (well well it may look suspicious for some people ^^) just handle your custom messages. I recently posted an example:

But you can also send simulated keystrokes ofc.

Edited by 636C65616E
Posted

So I am slowing understanding _SendMessage but I just can't wrap my head around the parameters. I am currently browsing the forums looking for examples of keystrokes and clicks using it.

In the meantime I have worked my way towards my end results but still can't solve the issue of clicking within a window and not activating it, I am thinking that once I understand _SendMessage I can essentially intercept a mouse click (_IsPressed) and Send it to the window at the clicked coordinates, therefore never actually focusing the window? Below is the progress I have come up with, but I am sure it's messy.

#include <Misc.au3>
#include <WinAPI.au3>
#include <WinAPISysWin.au3>

HotKeySet("`","focus")
HotKeySet("{F1}","msg")
Global $focus, $hwnd, $hwnd2

While 1
   Switch GUIGetMsg()
      Case -3
         Exit
   EndSwitch
   Sleep(100)
   check()
WEnd

Func focus() ;Sets the window to be interacted with
   $pos = _WinAPI_GetMousePos()
   $hwnd2 = _WinAPI_WindowFromPoint($pos)
   While _WinAPI_GetParent($hwnd2) <> 0
      $hwnd2 = _WinAPI_GetParent($hwnd2)
   WEnd
   $focus = _WinAPI_GetClassName($hwnd2)
EndFunc

Func msg() ;Checks that a window is set
   MsgBox(0, "", "Window set is: " & $focus)
EndFunc

Func check() ;Gets title and class of handle
   $pos = _WinAPI_GetMousePos()
   $hwnd = _WinAPI_WindowFromPoint($pos)
   While _WinAPI_GetParent($hwnd) <> 0
      $hwnd = _WinAPI_GetParent($hwnd)
   WEnd
   $title = WinGetTitle($hwnd)
   $class = _WinAPI_GetClassName($hwnd)
   If $class = $focus Then ;Checks on if current mouse position is over controlled window
   ;Routes all hotkeys minus tilde to controlled window
      For $i = 32 To 38
         HotKeySet(Chr($i), "Hotkeyfunc")
      Next
      For $i = 40 To 95
         HotKeySet(Chr($i), "Hotkeyfunc")
      Next
      For $i = 97 To 126
         HotKeySet(Chr($i), "Hotkeyfunc")
      Next
   Else
   ;Unroutes all hotkeys minus tilde to controlled window
      For $i = 32 To 38
         HotKeySet(Chr($i))
      Next
      For $i = 40 To 95
         HotKeySet(Chr($i))
      Next
      For $i = 97 To 126
         HotKeySet(Chr($i))
      Next
   EndIf
EndFunc

Func Hotkeyfunc() ;Sends keys to controlled window
   ControlSend($hwnd, "", "Edit1", @HotKeyPressed)
EndFunc

What I have accomplished is that you can set a window using tilde (`) ; the reasoning behind setting all ascii characters in a messy way skipping tilde; then when hovering over that window you send all keystrokes to that window, but not mouse clicks.

Posted
On 8/13/2021 at 11:45 AM, 636C65616E said:

The mechanism behind the magic of Send and ControlSend and anyway nearly any interaction with a window is based on a simple concept called the Window Message that handle all Window interactions (yeah fetching a Window Title need to use this mechanism for instance)

I will show you a quick example to be more clear. But here some readings:

EDIT: if you just want to 'communicate' with the window by your own, and not neceserraly use stuff the window handle initially (well well it may look suspicious for some people ^^) just handle your custom messages. I recently posted an example:

But you can also send simulated keystrokes ofc.

I have looked over your post multiple times and read up on the parameters but It's just too over my head. I don't understand any of it if I am being honest other than what it achieves when you set the parameters. I have searched all through the forums finding relating posts which most of them were left unresolved or the OP accepting ControlSend as an alternative. I have played around with ControlSend and ControlClick all day without achieving the results I am looking for (By utilizing MouseOnEvent UDF to steal the mouse click event and perform a function). The goal here is to send clicks and keystrokes to a window without taking focus, and being dynamic values (clicking directly underneath the cursor, and typing letter for letter keystrokes). 

Posted

I will look a bit, but to be fair why do you need to automate such actions ? For which programm ? (tbh it looks suspicious)

Do you know what the window looks like ? Do you have any infos about the controls inside it ?

Posted
1 minute ago, 636C65616E said:

I will look a bit, but to be fair why do you need to automate such actions ? For which programm ? (tbh it looks suspicious)

Do you know what the window looks like ? Do you have any infos about the controls inside it ?

The program I am looking to control is any single window of choice. I understand how it can look suspicious, I am currently playing between both Notepad and Chrome trying to solve this.

Specifically, I came up with this idea as a friends work computer monitors their activity and I figured it would be neat to allow interaction with Chrome or other applications while maintaining focus of "work related programs". Allowing you to browse the internet without the monitoring application picking up on it.

Seemed like a good chance for me to write something up and practice in the process but I quickly realized how much harder it was than I thought it would be.

Posted

Well, ok, but to be fair, it could be possible that this kind of programm hooks every window and inspects the msg flow, so active or not will change nothing (anyway yeah, it might be a bit overkill when only hooking the active window could be enough), but why not.

Gonna try to find you an answer, but not now because I got some work to do for few days.

Posted
5 minutes ago, 636C65616E said:

Well, ok, but to be fair, it could be possible that this kind of programm hooks every window and inspects the msg flow, so active or not will change nothing (anyway yeah, it might be a bit overkill when only hooking the active window could be enough), but why not.

Gonna try to find you an answer, but not now because I got some work to do for few days.

Understandable, and I agree with working around this program may achieve nothing it still seemed like a very fun project to broaden my knowledge into more difficult tasks such as your suggestions. So even at minimum I would like to see some simple examples of its use for an absolute beginner if you can assist.

I appreciate the help so far and hope that this thread doesn't end up lost. You have definitely raised my curiosity with Sending and Posting.

  • 3 weeks later...
Posted (edited)
On 8/12/2021 at 10:34 PM, kjpolker said:

EDIT: What I mean by ControlSend limitations is I think for dynamic input I would have to assign each key to call a function to ControlSend that key pressed to the window? Since the goal is to send any and all input to that window itself, and not a static string.

 

 

You can use _IsPressed() to get actual pressed key and after translation from hexkey format to char format use it in ControlSend().

But be very carrefull about posting such script here on the forum as this is very close to so called "keylogger" which is forbidden here,

see forum rules!

Edited by Zedna
  • Moderators
Posted

kjpolker,

Quote

Allowing you to browse the internet without the monitoring application picking up on it.

Does this mean that you are trying to bypass some form of monitor program which checks to make sure that you actually working in the expected window? Would this perhaps be installed by your employer to confirm that you are actually doing what you are being paid for?

And please take Zedna's comments to heart - I suggest you read this announcement before you do anything else.

M23

P.S. And just to be absolutely clear - this is the Mod team determining the legality of the thread, so everyone else please keep out.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

I completely understand. Let me add some clarity since my original post. I was looking for a way to simply interact with any window while maintaining the integrity of focus in another window. This was to be more of a tool and not for harmful or wrong behavior. Such that there are no issues with the employer to see that youtube is being watched while in the background, for a podcast, music videos, etc... I was reaching out to learn if this is a possibility to be able to in fact interact with a window (any window) without giving it focus, to include mouse clicks and typing. I characterize it as curiosity, but if this is in fact over the line then I apologize and will continue my research on the matter.

It has since evolved into me being interested in how SendMessage and PostMessage work as it is so above my head. In the meantime I ended up launching YouTube as a 'widget' if you will in a small popup window that remains on-top of other windows so you can work with background music/video. I see several examples of postmessage but none of it I can dissect fully. I was hoping to understand how to utilize @hotkeypressed with postmessage and not at all "capture" keystrokes. I have zero desire to log strokes or clicks, just relay them to unfocused window while the mouse is hovering over that window.

  • Moderators
Posted

kjpolker,

OK, happy for the thread to continue.  But please bear in mind the "keylogger" restrictions - I know you are not looking to create one, but they apply to ALL code posted here.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...