KeyPressProcessTool 0.0.1

dotnet tool install --global KeyPressProcessTool --version 0.0.1
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local KeyPressProcessTool --version 0.0.1
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=KeyPressProcessTool&version=0.0.1
nuke :add-package KeyPressProcessTool --version 0.0.1

<img src="Icon.png" width="135" style="display: block; margin-right: auto; margin-left: auto; width:200px"/>

<img src="Icon.png" width="35"/> KeyPressProcessTool

Description

This tool for Windows sends key presses to other processes.
This is useful for automation, to automatically close popups,
or anything that doesn't have any other way to automate other than actually pressing keys into an app.
Mouse control is not supported, try to use the {TAB} and {ENTER} keys to navigate through forms.
All keyboard keys are available, including windows key, Alt, Control, Escape, F1, F2, etc.
Waiting periods between keystrokes can be added with A{WAIT-200}B to add 200 milliseconds between pressing A and B.

User's Guide

Requirements

  • Windows OS (it has a dependency on Windows Forms to send key strokes).
  • dotnet 7 Runtime.

How to install

  • Download the latest binaries from the releases section on GitHub.
  • Or alternatively compile the project yourself by cloning this repo, optionally use the /scripts/Build.ps1.

Configuration

Can be done in 2 ways (in order of preference):

  • From the command-line parameters during the app invocation.
  • Editing AppSettings.json file before running the tool.

The available parameters (case-in-sensitive) are:

  • --Help: Display help: config and list of commands.
  • --Version: Display the version number.
  • -PN --Process:Name: Optional. Name of the process, must be an exact match without the extension, example "notepad".
  • -PT --Process:MainWindowTitle: Optional. Text that must be contained within the process's main window title. used to narrow down the filter between multiple instances of the same process. If left empty or whitespace it won't be used.
  • -PM --Process:TakeMax: Optional (defaults to null). If a number is specified, take only the first N processes from the list of matching processes. Useful to limit the impact during tests and prevent sending keys to the wrong process.
  • -DS --DelayToShowWindow: Optional (defaults to 500). Delay in milliseconds to wait before sending the keys and after the process is found and the process's main window is requested to be shown. This is to give the process some time to render the window in front, some apps may take more time than others, if the window doesn't have enough time to paint itself, the key-presses may not get registered by the app as expected.
  • -K --KeySequence: Optional. Keys to be sent to the target process as keyboard pressed keys.
  • -RE --Retry:Every: Optional. Timespan to wait between retries. https://learn.microsoft.com/en-us/dotnet/core/compatibility/serialization/6.0/timespan-serialization-format
  • -RM --Retry:MaxRetries: Optional. Maximum number of retries before quit trying.
  • -F --ExecuteForever: Optional (defaults to false). Set to true to execute forever in a loop, it will keep sending the keystrokes if it keeps finding the process match.
  • -DE --DelayBetweenExecutions: Optional (defaults to 5000). Delay time in milliseconds to wait after a successful execution occurs and before the next attempt. This is only used if configured to run more than once with ExecuteForever or ExecuteUntilMinSuccess > 1.
  • -MS --ExecuteUntilMinSuccess: Optional (defaults to 0). Select a number of times to successfully send the keys before finishing execution.
  • -RC --ReadLineOnClose: Optional (defaults to false). Enable this to make the program wait for an enter key before closing, useful to read the logs before closing, you probably want this off when running certain automations.

Edge cases

  • If the app runs without a Process:Name and without a Process:MainWindowTitle, then it will send the key-strokes to whatever is the active window at the moment, without waiting for the DelayToShowWindow period.
  • If the app runs with an empty KeySequence, it will just bring that App to the front as the active window.
  • If all parameters are empty, the app does nothing.

Command line

Config parameters can be set from the command line arguments as supported by dotnet's Microsoft configuration extensions.
Examples for the PowerShell console:

# Example with full param names:
.\KeyPressProcessTool.exe --Process:Name "notepad" --Process:MainWindowTitle "" --Process:TakeMax 1 --DelayToShowWindow 200 --KeySequence "Hello there!{ENTER}{TAB}How are you?" --Retry:MaxRetries 201 --Retry:Every "00:00:05" 

# Example with short param names:
.\KeyPressProcessTool.exe -PN "notepad" -PT "" -PM 1 -D 200 -K "Hello there!{ENTER}{TAB}How are you?" -RM 201 -RE "00:00:05" 

# Example with full-path and start-process (opens in a new cmd window):
Start "C:\KeyPressProcessTool.exe" -ArgumentList '-PN "notepad" -PT "" -PM 1 -D 200 -K "Hello there!{ENTER}{TAB}How are you?" -RM 201 -RE "00:00:05" ' 

For a list of special keys see the underlaying Windows Forms documentation.

AppSettings.json

Edit the optional AppSettings.json file located in the same folder as the tool's executable, before running the tool.
These settings will be taken as the default values when a parameter is not specified.
Example:

{
  "Process": {
	"Name": "notepad",
	"MainWindowTitle": "",
	"TakeMax": true
  },
  "DelayToShowWindow": 200,
  "KeySequence": "Hello there!{ENTER}{TAB}How are you?",
  "Retry": {
	"Every": "00:00:05",
	"MaxRetries": 200,
  },
  "ExecuteForever": false,
  "DelayBetweenExecutions": 0,
  "ExecuteUntilMinSuccess": 0
}

Extra Documentation

Product Compatible and additional computed target framework versions.
.NET net7.0-windows7.0 is compatible.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.0.1 209 6/18/2023