PostKey
- Last UpdatedOct 29, 2026
- 3 minute read
PostKey is a built-in function that posts a virtual-key code to the currently displayed project screen. In other words, it synthesizes a keystroke.
|
Function |
Group |
Execution |
String Exp. |
Windows |
Windows Embedded |
IoT View |
Thin Clients |
Mobile Access |
|---|---|---|---|---|---|---|---|---|
|
PostKey |
Module Activity |
Synchronous |
No |
Supported |
Supported |
Not supported |
Supported |
Not supported |
Syntax
PostKey(numKeydownOrKeyup,numwParam,numlParam)
PostKey ( { numKeydownOrKeyup | 0 | 1 } ,numwParam,numlParam)
numKeydownOrKeyup
A numeric option with the following possible values:
|
Value |
Description |
|---|---|
|
0 |
KeyDown event (that is, the key specified by numwParam is pressed) |
|
1 |
KeyUp event (that is, the key specified by numwParam is released) |
numwParam
The virtual-key code to be posted, in either decimal or hexadecimal format.
For a list of available codes, go to: msdn.microsoft.com/library/dd375731
numlParam
Additional message information.
This parameter is not typically used, so in most cases, the value should be 0 to indicate that there is no additional information.
Notes
If the Enforce Web functionality equivalence in local project screens option is selected in the project settings, this function cannot be called in VBScript Global Procedures, VBScript scripts (script groups), or other background tasks. This is because the function behaves differently depending on whether you view project screens locally (that is, on the same computer that hosts the project runtime) or remotely. For more information, see Preferences tab.
When this function is executed, it can only post either a KeyDown event or a KeyUp event, depending on the value that is specified for numKeydownOrKeyup. It cannot post both events at the same time. Therefore, in order to post a complete keystroke (that is, press and release), you must call this function twice โ once for each event โ as shown in the following example:
PostKey(0,36,0)
PostKey(1,36,0)
You can call other functions or execute other code between the two PostKey function calls, and if you do, that code will be executed as if the specified key is being held. You can even nest PostKey function calls in order to post key combinations (for example, Alt+F4).
Alternatively, if it is not feasible to call the PostKey function twice, you can use a Windows Shell object and the SendKeys method in VBScript in order to produce a similar effect. Unlike the PostKey function, however, the SendKeys method only needs to be called once in order to send a complete keystroke or even multiple keystrokes. For example:
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{HOME}"
Set WshShell = Nothing
For more information about using the SendKeys method like this, go to: social.technet.microsoft.com/wiki/contents/articles/5169.vbscript-sendkeys-method.aspx
Return value
This function returns no value.
Notes
VBScript uses special notation to indicate numbers that are of a different base. Prepending with &h indicates a hexadecimal number, while prepending with &o indicates an octal number. As such, if you use this function in VBScript and you want to specify a hexadecimal value for numwParam, you must use the special notation. For example, &h24 instead of the more typical 0x24.
Examples
Post the virtual-key code for the Home key, in decimal:
PostKey(0,36,0)
Post the virtual-key code for the Home key, in hexadecimal:
PostKey(0,0x24,0)
Post the virtual-key code for the Home key, in hexadecimal, using VBScript's special notation:
$PostKey(0,&h24,0)