Einzelnen Beitrag anzeigen

concept2015

Registriert seit: 22. Dez 2015
Ort: Nähe Dortmund
44 Beiträge
 
Delphi 7 Professional
 
#9

AW: Warten bis Event OnKeyDown abgearbeitet ist

  Alt 6. Jan 2017, 06:42
Ja, es wird zeichenweise befüllt.
Ja, dass Komma ist in der Zahl.

Hier der Link, in dem hier schon etwas besprochen wurde.

http://www.delphipraxis.net/110482-a...nd-delphi.html

Wie gesagt, alles klappt wunderbar, bis auf das Komma.

Da blicke ich nicht durch.

Der Str5:string sieht z.B. so aus 118,65
Im Editfeld wird aber das eingetragen 11865
Von Hand kann die Zahl aber selbstverständlich mit , eingegeben werden.

Es liegt eindeutig an der Routine.
Hab ein kleines Prog. geschrieben, nur mit dieser Routine und einem Editfeld ... kein Komma.
************************************** Testcode
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure PostKeyExHWND(hWindow: HWnd; key: Word; const shift: TShiftState;
specialkey: Boolean);
type
TBuffers = array [0..1] of TKeyboardState;
var
pKeyBuffers: ^TBuffers;
lParam: LongInt;
begin

(* check if the target window exists *)
if IsWindow(hWindow) then
begin
(* set local variables to default values *)
pKeyBuffers := nil;
lParam := MakeLong(0, MapVirtualKey(key, 0));

(* modify lparam if special key requested *)
if specialkey then
lParam := lParam or $1000000;

(* allocate space for the key state buffers *)
New(pKeyBuffers);
try
(* Fill buffer 1 with current state so we can later restore it.
Null out buffer 0 to get a "no key pressed" state. *)
GetKeyboardState(pKeyBuffers^[1]);
FillChar(pKeyBuffers^[0], SizeOf(TKeyboardState), 0);

(* set the requested modifier keys to "down" state in the buffer*)
if ssShift in shift then
pKeyBuffers^[0][VK_SHIFT] := $80;
if ssAlt in shift then
begin
(* Alt needs special treatment since a bit in lparam needs also be set *)
pKeyBuffers^[0][VK_MENU] := $80;
lParam := lParam or $20000000;
end;
if ssCtrl in shift then
pKeyBuffers^[0][VK_CONTROL] := $80;
if ssLeft in shift then
pKeyBuffers^[0][VK_LBUTTON] := $80;
if ssRight in shift then
pKeyBuffers^[0][VK_RBUTTON] := $80;
if ssMiddle in shift then
pKeyBuffers^[0][VK_MBUTTON] := $80;

(* make out new key state array the active key state map *)
SetKeyboardState(pKeyBuffers^[0]);
(* post the key messages *)
if ssAlt in Shift then
begin
PostMessage(hWindow, WM_SYSKEYDOWN, key, lParam);
PostMessage(hWindow, WM_SYSKEYUP, key, lParam or $C0000000);
end
else
begin
PostMessage(hWindow, WM_KEYDOWN, key, lParam);
PostMessage(hWindow, WM_KEYUP, key, lParam or $C0000000);
end;
(* process the messages *)
Application.ProcessMessages;

(* restore the old key state map *)
SetKeyboardState(pKeyBuffers^[1]);
finally
(* free the memory for the key state buffers *)
if pKeyBuffers <> nil then
Dispose(pKeyBuffers);
end; { If }
end;
end; { PostKeyEx }

procedure TForm1.Button1Click(Sender: TObject);
const
Str1: string = '2340';
Str2: string = '118,65';
var
Inp: TInput;
I: Integer;
begin
//*************************************** 1
Edit1.SetFocus;
for I := 1 to Length(Str1) do
begin
// press
Inp.Itype := INPUT_KEYBOARD;
Inp.ki.wVk := Ord(UpCase(Str1[i]));
Inp.ki.dwFlags := 0;
SendInput(1, Inp, SizeOf(Inp));

// release
Inp.Itype := INPUT_KEYBOARD;
Inp.ki.wVk := Ord(UpCase(Str1[i]));
Inp.ki.dwFlags := KEYEVENTF_KEYUP;
SendInput(1, Inp, SizeOf(Inp));

Application.ProcessMessages;
Sleep(120);
end;
//*************************************** 2
Edit2.SetFocus;
for I := 1 to Length(Str2) do
begin
// press
Inp.Itype := INPUT_KEYBOARD;
Inp.ki.wVk := Ord(UpCase(Str2[i]));
Inp.ki.dwFlags := 0;
SendInput(1, Inp, SizeOf(Inp));

// release
Inp.Itype := INPUT_KEYBOARD;
Inp.ki.wVk := Ord(UpCase(Str2[i]));
Inp.ki.dwFlags := KEYEVENTF_KEYUP;
SendInput(1, Inp, SizeOf(Inp));

Application.ProcessMessages;
Sleep(120);
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
// Bei Taste + befehl ausführen
if GetAsyncKeyState(VK_ADD) < 0 then Button1Click(Button1);
end;
end.

**************************************
Danke für euer Interesse.