How to receive information about pressing/releasing a key on the keyboard? Pascal code

How to receive information about pressing/releasing a key on the keyboard? My code is:

type
{$PACKRECORDS C}
TRawKeyInfo = record
TimeStamp : Int64;
KeyCode : DWord;
IsKeyDown : Boolean;
end;

const
KB_READ = 9999;

var
fd:LongInt;
S:TRawKeyInfo;
begin
fd:=fpopen(’/dev/input/keyboard/at/0’,O_RDWR);
if fd>=0 then
repeat
IoCtl(fd,KB_READ,@S);
WriteLn(S.TimeStamp,’ ‘,S.IsKeyDown,’ ',S.KeyCode)
until False;
end.

This is some kind of pascal dialect, right? I think it would be helpful if you put the language in the subject of the thread to specifically attract the people that are knowledgeable about it.

So, is your code working for you ? Does it compile without errors ? If not, which errors ?

Do you really need to communicate directly with the keyboard device this way? The protocol for that is undocumented.

Normally the input_server is in charge of communicating with the input devices. Then you can create a BApplication and hossibly a BWindow and implement the KeyDown/KeyUp methods to process input events (when your window is focussed, or with some extra work, you can do it globally even when your window is hidden)

1 Like