ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous Windows functions
  • To manage all the keyboard keys with KeyPressed:
  • Testing a key combination
  • Interrupting a process in a browse loop
  • Asynchronous status report
  • Using the KeyPressed function
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Checks which key is pressed.
Example
// Intégration du fichier "KeyConst.WL" pour gérer les touches du clavier
EXTERN "KeyConst.WL"
FOR I = 1 TO 5000
	HourGlass(True)
	Multitask(-1)
	// Vérification de la touche espace
	IF KeyPressed(VK_SPACE) = True THEN Info("Touche espace enfoncée")
	// Vérification de la touche A
	IF KeyPressed(Asc("A")) = True THEN Info("Touche A enfoncée")
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.
kpControlCtrl key.
kpEscapeEsc key.
kpLButtonLeft mouse button.
Java This constant is not available.
kpRButtonRight mouse button.
Java This constant is not available.
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 WINDEV "Personal\External" subdirectory.
<Change of status>: Optional boolean
  • True (default) for synchronous reporting: key currently pressed,
  • False to obtain an asynchronous report: the key has changed state since the last call to the function 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 include this file in your applications, you need to use the EXTERN keyword as follows:
    EXTERN "KEYCONST.wl"
  2. Use the constants in KeyPressed:
    IF KeyPressed(VK_Space) THEN ...
Remarks:
  • To manage character keys, simply use the ASCII code of that character (returned by Asc).
  • All the constants found in the KeyConst.WL file start with the letters VK_. These constants are displayed by the code completion in the code editor from the moment the file has been integrated with the EXTERN keyword.

Testing 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(Client, NumCli)
WHILE HOut() = False
	// Abandon par Echap?
	Multitask(-1) 
	IF KeyPressed(kpEscape) = True THEN BREAK
	// Traitement
	HReadNext(Client, NumCli)
END

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 line of code:
ToucheEnfoncée(<Touche>, Faux)
Java

Using the KeyPressed function

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

Last update: 09/21/2024

Send a report | Local help