Delphi For Loop Help

Please discuss general Delphi programming topics here.

Delphi For Loop Help

Postby Mike1990 » March 24th, 2010, 7:01 pm

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: March 24th, 2010, 6:56 pm

Re: Delphi For Loop Help

Postby Kambiz » March 24th, 2010, 7:34 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Re: Delphi For Loop Help

Postby Mike1990 » March 24th, 2010, 8:26 pm

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: March 24th, 2010, 6:56 pm

Re: Delphi For Loop Help

Postby Kambiz » March 25th, 2010, 1:07 am

It doesn't work because the logic is wrong.

You have to use a keyboard hook. Google 'keyboard hook' for more information.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Re: Delphi For Loop Help

Postby Mike1990 » March 25th, 2010, 4:51 pm

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: March 24th, 2010, 6:56 pm

Re: Delphi For Loop Help

Postby Kambiz » March 25th, 2010, 6:34 pm

Yes, client can send data to server if you are using sockets.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Re: Delphi For Loop Help

Postby Mike1990 » March 25th, 2010, 6:49 pm

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: March 24th, 2010, 6:56 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron