Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using the Post Key command to simulate a keystroke
Published On: March 28, 2002

Compatibility: 6.5.x, 6.7.x
Platforms: Mac, Win

With "Post Key" you can procedurally simulate a keystroke. Its effect is as if the user actually entered a character on the keyboard.

Let's take a look at a couple of examples:

Example 1


If you are not allowing Data entry into empty fields, you can do something like:

In the "On getting focus" Event for the field object method

If ($FieldisNotEmpty)

 post key(9)

End If

Post key(9) simulates a TAB and effectively moves the user to the next field.


Example 2


You can also do something like this:

If you have buttons which are assigned shortcut keys you can simulate the shortcut keys.

For example, if Shift-P is the shortcut key to button1, it is possible to do this:

If ($thisIsTrue)

Post key(80;Shift key mask)

`80 is the Ascii code for P. Shift key mask will simulate a shift key.

End if