|
|
|
|
|
- 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
KeyPressed (Function) In french: ToucheEnfoncée Checks which key is pressed.
EXTERN "KeyConst.WL"
FOR I = 1 TO 5000
HourGlass(True)
Multitask(-1)
IF KeyPressed(VK_SPACE) = True THEN Info("Space key down")
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.
<Constant>: Integer constant Identifies the control key: | | kpAlt | Alt key. | kpControl | Ctrl key. | kpEscape | Esc key. | kpLButton | Left mouse button.
| kpRButton | Right mouse button.
| kpShift | Shift 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) to get a synchronous status: key currently pressed,
- False to get an asynchronous status: the key status changed since the last call to KeyPressed.
Remarks To manage all the keyboard keys with KeyPressed: - 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:
- 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(Customer, CustNum)
WHILE HOut() = False
Multitask(-1)
IF KeyPressed(kpEscape) = True THEN BREAK
HReadNext(Customer, CustNum)
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:
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|