CAPL Script

KeyPressed

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Syntax

dword keypressed();

Function

This function returns the key code of a currently pressed key. If no key is being pressed it returns 0.. For example, pressing of a key can be queried in a timer function. The reaction can also be to letting go of a key.

Parameters

—

Return Values

Key code of pressed key. If the 8 lower bits do not equal 0,keypressedreturns the ASCII code of the next key in the keyboard buffer. If the 8 lower bits do not equal 0, the 8 upper bits represent the extended key code (see IBM PC Technical Reference Manual).

variables  {
  message 0x1A0 msg;
  msTimer myTimer;
  int running;
  int counter;
}
on timer myTimer  {
  if (keypressed())  {
    counter++;
    msg.DLC = 1;
    msg.byte(0) = counter;
    output(msg);
    setTimer(myTimer, 100);
  }
  else  {
    running = 0;
  }
}
on key 'r'  {
  // Ignore keyboard repeat while the timer is already running.
  if (running == 1) return;
  setTimer(myTimer, 0);
  running = 1;
}