ControlProcessLib : A "fake" ControlSend

Post your working scripts, libraries and tools for AHK v1.1 and older
off
Posts: 176
Joined: 18 Nov 2022, 21:54

ControlProcessLib : A "fake" ControlSend

06 Mar 2023, 20:20

This is a script i made for people that want to use ControlSend to a specific targeted window but it doesnt accept it.

How it Work?
This function activate and minimize targeted window, while sending keys between those. To avoid flickering screen, the window will be moved away from your screen, but still be activated. (This script targeted to be used for ppl that using the same screen for automating something (with only keyboard keys) while doing something else (ex: watching video).)

Code: Select all

; ControlProcessLibrary
; A "fake" ControlSend
;===
; This simple library contains function and
; acts like ControlSend but, for program/window
; that doesn't accept normal ControlSend.
;===
; How it work :
; This functions activate and minimize
; window you want, and send keys
; between those. To avoid flickering
; screen, the window will moved
; away from your screen, while still
; activating the window.
;===
; How to use :
; For _ControlSend
; _ControlSend("Keys", "WinTitle")
; > Keys = Any valid keyboard keys
; > WinTitle = Targeted Window Title
;
; For _WinRestore
; _WinRestore("WinTitle")
; > WinTitle = Targeted Window Title
;===
; Example Usage :
; #Include ControlProcessLib.ahk
;
; ^/:: ; ctrl+/
; _ControlSend("Hello{!}, You can send any key here. Even {enter} work, and {q 10}`nWork too :D", "ahk_exe Notepad.exe")
; return
; 
; Esc::
; _WinRestore("ahk_class Notepad")
; ExitApp
;===
_ControlSend(cp_key,cp_wintitle){
BlockInput, On
WinActivate, %cp_wintitle%
cp_height:=A_ScreenHeight+1000
cp_width:=A_ScreenWidth+1000
WinMove, %cp_wintitle%,, %cp_height%, %cp_width%
SendInput, %cp_key%
WinMinimize, %cp_wintitle%
BlockInput, Off
}

_WinRestore(cp_wintitle){
WinActivate, %cp_wintitle%
WinMove, %cp_wintitle%,, 0, 0
WinMinimize, %cp_wintitle%
BlockInput, Off
}
Example Usage:

Code: Select all

#Include ControlProcessLib.ahk

^/:: ; ctrl+/
_ControlSend("Hello{!}, You can send any key here. Even {enter} work, and {q 10}`nWork too :D", "ahk_exe Notepad.exe")
return

Esc::
_WinRestore("ahk_class Notepad") ; putting these before ExitApp to make sure the moved window will be restored before the script goes off
ExitApp
mudslap
Posts: 5
Joined: 10 Oct 2022, 18:44

Re: ControlProcessLib : A "fake" ControlSend

08 Mar 2023, 12:15

it works but i can't open the program after it is minimized
gya
Posts: 25
Joined: 04 Nov 2021, 01:22

Re: ControlProcessLib : A "fake" ControlSend

08 Mar 2023, 16:23

@off
Thank you for your proposal which may be useful.
Do you know this? :

[Script] Dock-It ( window docker ) - AutoHotkey Community @ viewtopic.php?f=6&t=103165&sid=eee02b20f1686b145ddbde1d92bd48c1

With kind regards (Windows 10 - 64 bits).
off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: ControlProcessLib : A "fake" ControlSend

08 Mar 2023, 18:53

@mudslap
You need to use _WinRestore to restore the window,
Its recomended to put _WinRestore on Hotkey that terminate the script, for example

Code: Select all

Esc::
_WinRestore("ahk_exe Notepad.exe")
ExitApp
Return ; you dont need return if you put this Esc on the bottom of your script
But you can also just have a hotkey to restore without terminating script,

Code: Select all

^+r::_WinRestore("ahk_exe Notepad.exe) ; ctrl shift r


@gya
I never saw it before, ill try to look into it, Thanks!
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: arrondark, Chunjee, gwarble and 72 guests