alternetsoft / AlternetUI

MIT License
22 stars 2 forks source link

Add SendKeys #95

Closed neoxeo closed 5 months ago

neoxeo commented 6 months ago

@generalloki

Could you add SendKeys (https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys?view=windowsdesktop-8.0)

Thanks

generalloki commented 6 months ago

@neoxeo

BTW If you find SendKeys analogue in WxWidgets I will add this feature much quicker.

neoxeo commented 6 months ago

@generalloki

I will looking for that and give you results.

neoxeo commented 6 months ago

@generalloki

Interesting links : Edit: https://docs.wxwidgets.org/trunk/classwx_u_i_action_simulator.html https://github.com/lucassklp/Desktop.Robot/tree/main https://github.com/lallousx86/SendKeys

generalloki commented 6 months ago

@neoxeo

Thanks! I beleive I can import wxUIActionSimulator. They write that this class currently doesn't work when using Wayland with wxGTK. But, anyway this would be a simplest solution

generalloki commented 6 months ago

Added UIActionSimulator. And example is in 'Samples' page of ControlsSample, 'Action Simulator Sample'. It works ok on Windows and Ubuntu 20.

neoxeo commented 6 months ago

@generalloki

Thanks a lot !

neoxeo commented 5 months ago

@generalloki

OS : Windows

Version : 0.9.516

I have questions about SendKeys, SendChar and NativeKeyCode and Keys.

Here is my tool to test them : image

And project : Tests_SendKeys.zip

I don't understand why sendchar does not accept "Keys.V" but only "NativeKeyCode" I don't understand why "simulator.SendKeyDown(NativeKeyCode.ControlV);" doesn't send "CTRL+V" I don't understand why KeyUp and KeyDown not have same works SendText have problem when you send text with numbers or special char

generalloki commented 5 months ago

Thanks for sending the test project. After studying it:

An example:

                        var condition = true;
                        simulator.SendMouseMoveIf(ref condition, button1, (5, 5));
                        simulator.SendMouseClickIf(ref condition);
                        simulator.SendMouseMoveIf(ref condition, editor, (5, 5));
                        simulator.SendMouseClickIf(ref condition);
                        simulator.SendTextIf(ref condition, "Hello");
                        simulator.SendMouseMoveIf(ref condition, button2, (5, 5));
                        simulator.SendMouseClickIf(ref condition);

                        Clipboard.SetText($"({++counter}) Text from clipboard using Ctrl+V");
                        editor2.Focus();
                        editor2.Text = string.Empty;
                        simulator.SendKeyIf(ref condition, NativeKeyCode.V, UIActionSimulator.KeyModifier.Control);
                        return condition;

As to your questions:

The major problem is that Ubuntu 23 and maybe other version is not supported and we can just wait until wxWidget add it's support.

I will post an update to action simulator on these days and let you know here when it's uploaded.

generalloki commented 5 months ago

Update is in Master

neoxeo commented 5 months ago

@generalloki

Thanks a lot for all these new options. I have updated testProject and all work fine, except SendText (but you have explained why) and SendKeyUp. image

Here is the new TestProject : TestProject2.zip

generalloki commented 5 months ago

I beleive SendKeyUp works as expected. You should not use it without SendKeyDown. All controls suppose to receive KeyDown first and only after that KeyUp. So it is better to use SendKey and don't bother with all these.

neoxeo commented 5 months ago

Ok, if though that KeyUp should work like down. Now, I will only use SendKey.

Do you want to keep this issue opened to solve Send text when WxWidget fix it ? Else, it can be close.

Thanks.

generalloki commented 5 months ago

I beleive we can close it for now, as any improvements in wxWidgets simulator part will be reflected automatically when we switch to new wxWidgets version.