Difference between revisions of "GetKeyState"

From SCAR Divi Manual
Jump to: navigation, search
 
Line 53: Line 53:
 
   if (Num >= 0) and (Num =< 9) then
 
   if (Num >= 0) and (Num =< 9) then
 
     Result := GetKeyState(VK_NUMPAD0 + Num);
 
     Result := GetKeyState(VK_NUMPAD0 + Num);
 +
end;
 +
</source>
 +
 +
===IsFunctionKeyDown===
 +
<source lang="scar">
 +
function IsFunctionKeyDown(const Key: Byte): Boolean;
 +
begin
 +
  Result := False;
 +
  case Key of
 +
    0: Result := GetKeyState(VK_SHIFT);
 +
    1: Result := GetKeyState(VK_CONTROL);
 +
    2: Result := GetKeyState(VK_MENU);
 +
    3: Result := GetKeyState(VK_LSHIFT);
 +
    4: Result := GetKeyState(VK_LCONTROL);
 +
    5: Result := GetKeyState(VK_LMENU);
 +
    6: Result := GetKeyState(VK_RSHIFT);
 +
    7: Result := GetKeyState(VK_RCONTROL);
 +
    8: Result := GetKeyState(VK_RMENU);
 +
  end;
 
end;
 
end;
 
</source>
 
</source>

Latest revision as of 15:31, 10 November 2012

Definition

function GetKeyState(const VKey: Byte): Boolean;

Availability

SCAR Divi 3.35 > Current

Description

Gets the state of a key asynchronously from the active client. This means that it will return true if the key was pressed since the last time you called the function.

Example

begin
  repeat
    Wait(500)
  until GetKeyState(VK_DOWN);
  WriteLn('Pressed down');
end.

Implementations

IsArrowDown

function IsArrowDown(const Num: Byte): Boolean;
begin
  Result := False;
  case Num of
    0: Result := GetKeyState(VK_UP);
    1: Result := GetKeyState(VK_RIGHT);
    2: Result := GetKeyState(VK_DOWN);
    3: Result := GetKeyState(VK_LEFT);
  end;
end;

IsFKeyDown

function IsFKeyDown(const Num: Byte): Boolean;
begin
  Result := False;
  if (Num > 0) and (Num < 25) then
    Result := GetKeyState(VK_F1 + Num - 1);
end;

IsNumpadKeyDown

function IsNumpadKeyDown(const Num: Byte): Boolean;
begin
  Result := False;
  if (Num >= 0) and (Num =< 9) then
    Result := GetKeyState(VK_NUMPAD0 + Num);
end;

IsFunctionKeyDown

function IsFunctionKeyDown(const Key: Byte): Boolean;
begin
  Result := False;
  case Key of
    0: Result := GetKeyState(VK_SHIFT);
    1: Result := GetKeyState(VK_CONTROL);
    2: Result := GetKeyState(VK_MENU);
    3: Result := GetKeyState(VK_LSHIFT);
    4: Result := GetKeyState(VK_LCONTROL);
    5: Result := GetKeyState(VK_LMENU);
    6: Result := GetKeyState(VK_RSHIFT);
    7: Result := GetKeyState(VK_RCONTROL);
    8: Result := GetKeyState(VK_RMENU);
  end;
end;

See Also