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
  • Keys of Pocket PCs and Smartphones
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.
Example
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)
Windows Mobile
// -- Initialization code of project
// Include the "KeyConst.WL" and "WinConst.WL" files
EXTERN "KeyConst.WL"
EXTERN "WinConst.WL"

// -- Initialization code of window
// Intercept the Pocket PC key that is pressed
Event("MoveImage", "Window1.*", WM_KEYDOWN)
// -- "MoveImage" procedure
PROCEDURE MoveImage()
// Move the "IMG_MyImage" Image control with the arrows of the Smartphone or Pocket PC
// Right arrow: move to the right
IF KeyPressed(VK_RIGHT) THEN IMG_MyImage..X = IMG_MyImage..X + 10
// Left arrow: move to the left
IF KeyPressed(VK_LEFT) THEN IMG_MyImage..X = IMG_MyImage..X - 10
// Up arrow: move to the top
IF KeyPressed(VK_UP) THEN IMG_MyImage..Y = IMG_MyImage..Y + 10
// Down arrow: move to the bottom
IF KeyPressed(VK_DOWN) THEN IMG_MyImage..Y = IMG_MyImage..Y - 10
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:
kpAltAlt key.
kpLButtonLeft mouse button.
kpRButtonRight mouse button.
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.
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...
Notes:
  • 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
Windows Mobile

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)
Windows Mobile

Keys of Pocket PCs and Smartphones

The diagrams below present the WLanguage constants associated with the keys.
Component : wd240std.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Video KeyPressed
https://youtu.be/d3vm47ERJS8

https://windevdesenvolvimento.blogspot.com/2019/04/dicas-2082-windev-comandos-57-keypressed.html
// PROJETO INICIAL - CODE

EXTERN "KEYCONST.wl"

// EXIT FROM EDT_NOME
IF EDT_NOME="" THEN
Info("FAVOR INFORMAR NOME")
ReturnToCapture(EDT_NOME)
END

// WHENEVER MODIFYING EDT_NOME
IF KeyPressed(kpControl) THEN
ReturnToCapture(EDT_cpf)
END

amarildo
23 Apr. 2019
Observações Importantes
PARA FUNCIONAR:

1 - Copie o arquivo "KeyConst.WL" do diretório do
C:\Windev XX\KeyConst.WL copiar para o teu projeto em
C:\My Projects\TheBestProject\
KeyConst.WL

2 - No Project Explorer, em "P" (Project) / CODE GLOBAL / Initializing
Informe o seguinte codigo:

EXTERN "KeyConst.WL"

3 - No Project Explorer em "Other", Adding Elements
Localize o arquivo: "KeyConst.WL" e OK

Pronto agora só usar

Ah... no caso de querer detectar o Enter o comando é
VK_RETURN = ENTER

Se abrir o KeyConst.WL no Notepad poderá ver os demais comandos ou analisar eles pelo help mesmo, onde a documentação é show de bola!

Bons estudos!
BOLLER
05 Apr. 2019
exemplo keypressed
Message("Aguarde.. Esperando retorno do Sefaz.")
Wait(500)
FOR X = PROGBAR_Progress_bar..MinValue _TO_ PROGBAR_Progress_bar..MaxValue
// FORÇAR A SAIDA DESSE FOR., OU PODERIA SER UM LOOP
Message("Espaco Sair..7."+n_contador_)
Multitask(-1)
IF KeyPressed(VK_SPACE)=True THEN
// VERIFICANDO SE É APERTADO A TELCA ESPACO
// PODERIA SER QUALQUER TECLA
BREAK
END
n_contador_++
Message("")
s_retorno_xml=s_retorno1_xml
IF fFileExist(s_retorno_xml) THEN
ler_retorno(s_retorno_xml)
BREAK
ELSE
s_retorno_xml=s_retorno2_xml
IF fFileExist(s_retorno_xml) THEN
ler_retorno(s_retorno_xml)
BREAK
END
END
PROGBAR_Progress_bar..Visible=False
END
amarildo
13 Nov. 2018