Delphi For Loop Help

If you have a programming question, please feel free to post it here. Non-programming questions will be moved to Miscellaneous or deleted.

Delphi For Loop Help

by Mike1990 » 24/03/10 19:01

This is the code i use, but the timer for loop doesn't terminate and shows a message box up loads of times. It should only show the message box up when a key is pressed and should only show it once

Code: Select all
procedure TForm2.keyloggerTimer(Sender: TObject);
var
i: Integer;
key: String;
begin

  for i := 97 to 122 do
  begin
    if GetAsyncKeyState(i) <> 0 then
      key := key + Chr(i);

    ShowMessage(key);
  end;

end;


Could anyone help me?
Mike1990
Active Member
Active Member
 
Posts: 5
Joined: 24/03/10 18:56

Re: Delphi For Loop Help

by Kambiz » 24/03/10 19:34

Try this code:

Code: Select all
procedure TForm2.keyloggerTimer(Sender: TObject);
var
  i: Integer;
  key: String;
begin
  key := '';
  for i := 97 to 122 do
  begin
    if GetAsyncKeyState(i) <> 0 then
      key := key + Chr(i);
  end;
  if key <> '' then
  begin
    keylogger.enabled := False;
    ShowMessage(key);
    keylogger.enabled := True;
  end;
end;
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site
User avatar
Kambiz
Administrator
Administrator
 
Posts: 1952
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: Delphi For Loop Help

by Mike1990 » 24/03/10 20:26

Thanks for the help but still not working

Code: Select all
procedure TForm2.keyloggerTimer(Sender: TObject);
var
i: Integer;
key: String;
begin
  key := '';
  for i := 97 to 122 do
  begin
    if GetAsyncKeyState(i) <> 0 then
      key := key + Chr(i);
  end;
  if key <> '' then
  begin
    keylogger.enabled := False;
    ShowMessage(key);
    keylogger.Enabled := True;
  end;
end;


I enable the keylogger through a client and the client sends the server the enable keylogger command. When the server receives the enable keylogger command the server enables the timer.

If you could help me fix this, it would really be appreciated.

Thank you
Mike1990
Active Member
Active Member
 
Posts: 5
Joined: 24/03/10 18:56

Re: Delphi For Loop Help

by Kambiz » 25/03/10 01:07

It doesn't work because the logic is wrong.

You have to use a keyboard hook. Google 'keyboard hook' for more information.
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site
User avatar
Kambiz
Administrator
Administrator
 
Posts: 1952
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: Delphi For Loop Help

by Mike1990 » 25/03/10 16:51

I've got it sorted now thank you for your help, but one last question.

Is it possible to send data back to the client from the server?

Thank you
Mike1990
Active Member
Active Member
 
Posts: 5
Joined: 24/03/10 18:56

Re: Delphi For Loop Help

by Kambiz » 25/03/10 18:34

Yes, client can send data to server if you are using sockets.
Kambiz

Donate a cup of food for free: Click to Give @ The Hunger Site
User avatar
Kambiz
Administrator
Administrator
 
Posts: 1952
Joined: 07/03/03 19:10
Location: Tehran, Iran

Re: Delphi For Loop Help

by Mike1990 » 25/03/10 18:49

I can send data from the client to the server but i can't seem to be able to send data back from the server to the client

I'm using TClientSocket and TServerSocket, is it possible?
Mike1990
Active Member
Active Member
 
Posts: 5
Joined: 24/03/10 18:56


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 0 guests