Simulate an automatic enter key press

Hi All.

A question for something that I hope is possible, but might not be.

In my screensaver program, after the user enters when they want a the program to end, after x minutes, i have them press “return” - Mac - Chr(13) - so they can enter more than one character in the appropriate textfield.

I want to, when the program is opened automatically generate a keypress in the textfield. (I load the previous preferences the user had on startup).

I’ve tried appending Chr(13), Keyboard, etc. but it is fighting me tooth and nail.

Any ideas?

And Happy Gnu Year.

Chr(13) is a special key in that the OS responds to it. What do you expect it to do? Normally, it fires the default button, but your description is a little vague. Especially the part about “so they can enter more than one character”. That is a nonstandard use of the Return key. Can you provide more details?

Not quite sure what you’re asking or what functionality you’re trying to implement. Have you tried adding EndOfLine?

If you truly want to emulate a keypress, the way I’ve done it before was with RemoteControlMBS. But you’ll need to give your application permissions to do this on MacOS in Settings → Accessibility.

1 Like

TextField is a single line of text without line break and the Enter Key raise a event, it call a method that user had input something, if unhandled it called a default button then.
TextArea can handle line breaks.

usual u read/write data from/to text boxes via .Text but not simulate user input.

i guess you will repeat the enter key from screensaver in the (same) app which get then visible.

Hi All.
Thanks for the reply.

I was thinking of having a button (invisible) that will that I can use the .Press on.

I think have tried EndOfLine, but will try again… I have tried so many things. Just in case.

Stay tuned.

Regards

Please do not execute Code inside a Button by virtually pressing it. Instead, put the to be executed Code into a Method and call that Method from within the Button.Pressed Event and from everywhere else you want to execute the Code from.

2 Likes

Ok.

So if I can ask, the reason for this is so that is accessible by any control, or is there another reason?

Regards

Simulating user input when you have no legitimate reason is a bad user experience for one. Additionally, the user gets alerted by macOS that your app wants to simulate input and provides the option to allow or deny the control. Should they deny access, your app can no longer function.

4 Likes