I was trying to use GetKeyBuffer and couldn't find a good example so i figured i would share with everyone my solution in Delphi.
Declare this outside of your loop:
KeyBuffer: PSafeArray;
Init your PSafeArray
Procedure doInit;
var
sab: TVarArrayBound;
begin
Sab.ElementCount := 1;
Sab.LowBound := 0;
KeyBuffer := SafeArrayCreate(varDispatch,1,NumPressed);
end;
Call this in your loop to handle the keys.
Function DoKeys(InputFactory: TTVInputEngine);
type
Key = Array of TV_KEYDATA;
var
x: Integer;
NumPressed: Integer;
KeyData: Pointer;
begin
if KeyBuffer <> nil then
begin
InputFactory.GetKeyBuffer(KeyBuffer, NumPressed);
if (NumPressed > 0) and (keyBuffer <> nil) then
begin
for x := 0 to NumPressed - 1 do
begin
SafeArrayAccessData(KeyBuffer, KeyData);
if (Key(KeyData)[x].Pressed) then
if (Key(KeyData)[x].Key = TV_KEY_BACKSPACE) then
begin
DoBackspace;
end
else
TypeKey(Key(KeyData)[x].key);
end;
end;
end;
end;
On Destroy you may want to call : SafeArrayDestroy(KeyBuffer);
BR