Autor Beitrag
arcitC|Crash
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 88


D4 weiter weiß ich net
BeitragVerfasst: Sa 06.08.05 23:09 
Also ich hab beim Client das Ereignis TForm.OnKeyPress
Der Code sieht so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  Client.Socket.SendText(key);
  Label1.caption := key;
end;


Beim Server soll dann der Tastendruck simuliert werden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.ServerClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var rec : string;
begin
  rec := Socket.ReceiveText;
  keybd_event(ord(STRtoINT(rec)),ord(STRtoINT(rec)),0,0);
  keybd_event(ord(STRtoINT(rec)),ord(STRtoINT(rec)),KEYEVENTF_KEYUP,0);
end;


So, beim Compilen gibt es auch keine Probleme, aber wenn ich dann beim Client eine Taste drück, bekomme ich einen Fehler, dass die jeweilige Taste kein gültiger Integerwert ist...
Wo ist der Fehler?

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt.
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Sa 06.08.05 23:29 
user profile iconarcitC|Crash hat folgendes geschrieben:
ausblenden Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  Client.Socket.SendText(key);
  Label1.caption := key;
end;



schau mal genau hin: key:char --> Das kann gar kein Integerwert sein
musst du wahrscheinlich umwandeln
arcitC|Crash Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 88


D4 weiter weiß ich net
BeitragVerfasst: Sa 06.08.05 23:34 
Ja aber wie wandel ich das um?
Beim Server hab ich ja doch STRtoINT benutzt.
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 07.08.05 05:30 
Mit Ord bzw Chr

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: So 07.08.05 08:45 
Bei chr wird als Parameter eine Zahl angegeben, die dann in einen ASCII-Letter vertauscht wird, bei Ord ein Buchstabe!

_________________
Aus dem Urlaub zurück!
arcitC|Crash Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 88


D4 weiter weiß ich net
BeitragVerfasst: So 07.08.05 12:39 
Ich weiß ehrlich gesagt auch gar nicht, was ich umwandeln soll. Dieser Befehl keybd_event, was für einen Wert will er denn haben? Word? Char? String? Integer?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var rec : string;
begin
  rec := Socket.ReceiveText;
  keybd_event(ord(rec),ord(rec),0,0);


In Word umwandeln geht nicht, da kommt immer "[Fehler] Unit2.pas(32): Inkompatible Typen"

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var rec : string;
begin
  rec := Socket.ReceiveText;
  keybd_event(STRtoINT((rec)),STRtoINT((rec)),0,0);
  keybd_event(ord(STRtoINT(rec)),ord(STRtoINT(rec)),KEYEVENTF_KEYUP,0);


So geht es zwar, aber wenn ich dann eine Taste drücke, sagt er mir, das das kein gültiger Integerwert war.

Also ich gehe mal davon aus, das ich den erhaltenen String entweder in Word (ord) oder in Char (chr) umwandeln muss. Stimmt, klingt fast logisch^^
Aber mit welchem Befehl? StrtoCHR gibt es nicht und STRtoORD auch nicht...

Edit: Ach nee, Ord geht ja auch nicht, das hatte ich ja oben schon mit (ord(rec))...
Also muss ich das in Char umwandeln...aber wie?

Moderiert von user profile iconmatze: Code- durch Delphi-Tags ersetzt.
tigger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25

Win 2k, XP Pro

BeitragVerfasst: So 14.08.05 15:30 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var rec : string;
begin
  rec := Socket.ReceiveText;
  keybd_event(ord(rec),ord(rec),0,0);


es müsste gehen, wenn du rec den typ char gibst

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
arcitC|Crash Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 88


D4 weiter weiß ich net
BeitragVerfasst: So 14.08.05 16:05 
nee hier steht nichts------------
tigger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 25

Win 2k, XP Pro

BeitragVerfasst: Di 16.08.05 10:36 
ups, das war falsch, du musst ord ein char übergeben, nicht einen string