PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • To manage all the keyboard keys with KeyPressed:
  • Running the test of a key combination
  • Interrupting a process in a browse loop
  • Asynchronous status report
  • Using the KeyPressed function
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Checks which key is pressed.
Versions 15 and later
Java This function is now available for Java applications.
New in version 15
Java This function is now available for Java applications.
Java This function is now available for Java applications.
Example
// Include the "KeyConst.wl" file to manage the keyboard keys
EXTERN "KeyConst.WL"
FOR I = 1 TO 5000
HourGlass(True)
Multitask(-1)
// Check Space key
IF KeyPressed(VK_SPACE) = True THEN Info("Space key down")
// Check A key
IF KeyPressed(Asc("A")) = True THEN Trace("A key down")
END
HourGlass(False)
Syntax
<Result> = KeyPressed(<Constant> [, <Change of status>])
<Result>: Boolean
  • True if the control key is pressed or if its status changed since the last call to KeyPressed,
  • False otherwise.
Java Specific operating mode:
  • True if the control key is currently pressed,
  • False otherwise.
<Constant>: Integer constant
Identifies the control key:
kpAltAlt key.
kpLButtonLeft mouse button.
Java This constant is not available.
kpRButtonRight mouse button.
Java This constant is not available.
kpControlCtrl key.
kpEscapeEsc key.
kpShiftShift key.

Additional constants are available in the "KeyConst.wl" file. These constants are used to identify all the keyboard keys. This file is available in the "\Personal\Extern" directory of WINDEV or WINDEV Mobile. See remarks for more details.
<Change of status>: Optional boolean
  • True (default value) to get a synchronous status: key currently pressed,
  • False to get an asynchronous status: the key status changed since the last call to KeyPressed.
Java This parameter is ignored. The status code is always synchronous.
Remarks

To manage all the keyboard keys with KeyPressed:

  1. Include the KeyConst.WL file in your project. This file associates a specific constant with each keyboard key. This file is available in the \Personal\Extern directory of WINDEV. To integrate this file into your applications, it is necessary to use the keyword EXTERN as follows:
    EXTERN "KEYCONST.wl"
  2. Use the constants in KeyPressed:
    IF KeyPressed(VK_Space) THEN...
Remarks:
  • To manage the character keys, use the ASCII code of the character (returned by Asc).
  • All the constants found in the KeyConst.WL file start with the letters VK_. These constants are proposed by the automatic completion in the code editor as soon as the file was included by the EXTERN keyword.

Running the test of a key combination

To run the test of a key combination, run the test of two keys pressed:
IF KeyPressed(kpShift) AND KeyPressed(VK_TAB) THEN
Trace("OK")
END

Interrupting a process in a browse loop

In a loop, to interrupt the process by pressing Esc, Multitask must be called before KeyPressed.
Example:
HReadFirst(Customer, CustNum)
WHILE HOut() = False
// Abandon via Esc?
Multitask(-1)
IF KeyPressed(kpEscape) = True THEN BREAK
// Process
HReadNext(Customer, CustNum)
END
WINDEVWindowsUser code (UMC)

Asynchronous status report

To avoid retrieving a key that was pressed beforehand (in another process for example), the status of the key to test must be reinitialized by the following code line:
KeyPressed(<Key>, False)
Java

Using the KeyPressed function

The application must have focus in order for KeyPressed to check that the specified key is down.
Component : wd250std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment