dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

Mouse & Keyboard Input #7900

Closed manfredzimmer closed 2 years ago

manfredzimmer commented 2 years ago

Description

It would be great to have access to the mouse and keyboard. By this is meant that I would like to go with the mouse to coordinate XY and finally trigger a left click or right click. This function should also be possible with Windows, Linux & MacOS outside of the own application. For Android and iOS a "tap" could be implemented so that a button etc. can be clicked via code.

It would be extremely helpful to be able to trigger individual keyboard keys (independent of the current focus and also outside of the actual application). This could be implemented for Windows, Linux and MacOS.

Within Java you only need to use "Robot" class and everything is good to go. Within C# you need to sell your soul and first born child :p (in comparison).

Public API Changes


var mouse = new Mouse();
var mouseDelayInMs = 20;
var mouseReleaseInstantly = true;
var mouseScrollByPixel = 50;

mouse.MoveToX(500, mouseDelayInMs); // Move Mouse to X-Coordinate 500 (out of MAX-X-Value from current Monitor). Move with Delay (don't move instantly to the position, wait for XX ms before moving instantly to the Position)

mouse.MoveToY(400, mouseDelayInMs); // Move Mouse to Y-Coordinate 500 (out of MAX-Y-Value from current Monitor). Move with Delay (don't move instantly to the position, wait for XX ms before moving instantly to the Position)

mouse.MoveToXY(500, 400, mouseDelayInMs); // Move Mouse to X-Coordinate 500 (out of MAX-X-Value from current Monitor) and Y-Coordinate 400 (out of MAX-Y-Value from current Monitor). Move with Delay (don't move instantly to the position, wait for X ms before moving instantly to the Position)

mouse.MoveToCenterOf(AnyKindOfView, mouseDelayInMs); // Move Mouse to XY-Coordinate (Center of View) with XX Delay.

mouse.RightClick(mouseReleaseInstantly); // Default = false. if false, than press & hold right-click. if true, than do only 1 Click and release mouse-click instantly
mouse.Release(Mouse.RIGHT_CLICK); // Releases Right Mouse Click if there is any. If there is no Right-Click, than do nothing.
mouse.LeftClick(mouseReleaseInstantly); // Default = false. if false, than press & hold left-click.
mouse.Release(Mouse.LEFT_CLICK); // Releases Left Mouse Click if there is any. If there is no Left-Click, than do nothing.
mouse.ScrollUp(mouseScrollByPixel);
mouse.ScrollDown(mouseScrollByPixel);

var keyboard = new Keyboad();
var keyboardDelayInMs = 20;
var keyboardReleaseInstantly = true;
keyboard.press(Keyboard.Key.A); // Key "A" would be pressed til it is released
keyboard.release(Keyboard.Key.A) // Key "A" is released
keyboard.press(Keyboard.Key.A, keyboardReleaseInstantly); // Key "A" would be pressed and instantly released if "keyboardReleaseInstantly" is set to true
Keyboard.Key.A, Keyboard.Key.B, Keyboard.Key.C, Keyboard.Key.D, ... Keyboard.Key.ENTER, Keyboard.Key.SPACE, Keyboard.Key.BACKSPACE, Keyboard.Key.ALT, Keyboard.Key.SHIFT, ... etc.

### Intended Use-Case

I would like to develop a Autoclicker for each OS. This could be used for Clicker-Games like Cookie-Clicker etc.
ToolmakerSteve commented 2 years ago

Note that there are multiple earlier proposals/questions re keyboard/mouse support.

https://github.com/dotnet/maui/issues/3739 https://github.com/dotnet/maui/issues/3669 https://github.com/dotnet/maui/issues/4498

jfversluis commented 2 years ago

Duplicate of #3739