Autor Beitrag
Paddii
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 28

WinXP Prof.
Blitz3D, PureBasic 4, Delphi 6
BeitragVerfasst: Mi 04.10.06 09:46 
Hi Leute.

Ich Programmiere seit ca. 8 Monaten gelegentlich mit Delphi 6 und wollte ein Programm schreiben, dass einen Tastendruck simuliert, oder Tastenkombinationen. Bisher weiß ich nur, wie man einen tastendruck abfragt, aber leider nicht mehr.
Zum Beispiel soll das Programm zu einer bestimmten Uhrzeit (oder in gewisse Zeitabständen) einen druck auf F1 simulieren, sodass dann das geschieht, was mein Computer tun würde, wenn ich F1 gedrückt hätte.
Nun noch zu den tastenkombinationen, damit meine ich sowas wie: [Windowstaste] + E (Z.B. um den Explorer zu öffnen)

Vielleicht sollte ich dazu sagen, dass ich mir Delphi selbst beigebracht habe und deshalb vll nicht alles verstehe, was ihr schreibt, also bitte möglichst leicht erklären. ;-)

Freue mich schon auf Eure Antworten

Mfg Paddii
mister_x
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 85

Win 98, WIN 2000, WIN XP PRO
Delphi 2006
BeitragVerfasst: Mi 04.10.06 12:33 
Paddii Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 28

WinXP Prof.
Blitz3D, PureBasic 4, Delphi 6
BeitragVerfasst: Mi 04.10.06 17:10 
Thx

ich werds mal ausprobieren, wenn ich wieder Zeit hab, muss mal sehen ob ich damit klar komme, weil ich normalerweise immer erst alles verstehen will, bevor ich es benutze, aber vll kommt das ja noch.
ccdee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

WinXP, Linux
PHP, Delphi, VB, Cobal, Pascal
BeitragVerfasst: Mo 09.10.06 01:27 
Titel: hi
noch einfacher geht es hiermit:

du setzt einen Timer auf deine Form, setzt ihn zB auf 200ms und klicks 2 mal drauf

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm2.Timer1Timer(Sender: TObject);
begin
if
(GetAsyncKeyState(VK_F7) <> 0)
then Button1.Click;
end;



Dies ist jetzt ein Beispiel für die Taste F7
auf dieser Seite findest du eine Liste aller Virtual-Key Codes

msdn.microsoft.com/l.../VirtualKeyCodes.asp

MfG

CCDEE
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19312
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 09.10.06 03:40 
user profile iconccdee hat folgendes geschrieben:
noch einfacher geht es hiermit:

du setzt einen Timer auf deine Form, setzt ihn zB auf 200ms und klicks 2 mal drauf

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm2.Timer1Timer(Sender: TObject);
begin
if
(GetAsyncKeyState(VK_F7) <> 0)
then Button1.Click;
end;

Dies ist jetzt ein Beispiel für die Taste F7

Ähhh, die Frage war wie man einen Tastendruck simuliert! Nicht wie man nachsieht ob eine Taste gedrückt ist...
ccdee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

WinXP, Linux
PHP, Delphi, VB, Cobal, Pascal
BeitragVerfasst: Mo 09.10.06 11:25 
Titel: /
ups ja sorry, da bin ich wohl zu schnell über die Frage drübergeflogen ;)
Paddii Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 28

WinXP Prof.
Blitz3D, PureBasic 4, Delphi 6
BeitragVerfasst: Mi 11.10.06 08:45 
Danke Leute,

Hab mich für die zweite Methode im SwissDelphiCenter entschieden.
Das mit dem keybd_event.
Funktioniert super, genau wie ich es wollte.
Mordilion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 96

WinXP Prof., Win2k Prof.
Delphi 7 Prof., Delphi 2009 Prof., PHP4/5, CSS, HTML
BeitragVerfasst: Mi 11.10.06 10:16 
Hi,

ich hab soetwas selber mal gebraucht und mir dann eine eigene Methode gemacht, damit man auch Tastenkombinationen machen kann.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
procedure MyKeyEvent(Key: Byte; WaitForUp: Cardinal; DontUp, OnlyRelease: Boolean);
begin
  if not OnlyRelease then
  begin
    KeyBd_Event(Key, 000);
    if not DontUp then
    begin
      Sleep(WaitForUp);
      KeyBd_Event(Key, 0, KEYEVENTF_KEYUP, 0);
    end;
  end else
  begin
    KeyBd_Event(Key, 0, KEYEVENTF_KEYUP, 0);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  // Presses the Left Window Key and starts the Run
  MyKeyEvent(VK_LWIN, 0, True, False);
  Sleep(1);
  MyKeyEvent(Ord('R'), 0, False, False);
  Sleep(1);
  MyKeyEvent(VK_RETURN, 0, False, False);
  // At last we must release the Left Window Key
  MyKeyEvent(VK_LWIN, 0, False, True);
end;


Vielleicht hilft das einem weiter. ;)

_________________
Für das große Chaos haben wir Computer. Die übrigen Fehler machen wir von Hand.
Der Mensch ist das wichtigste und kostbarste Peripheriegerät einer Computeranlage.
Paddii Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 28

WinXP Prof.
Blitz3D, PureBasic 4, Delphi 6
BeitragVerfasst: Mo 16.10.06 16:55 
Also ich hab jetzt damit mal nen bissl rumgespielt, aber ich weiß nicht wie ich einen Doppelpunkt hinbekomme.
In der Liste für die virtual keys steht was von wegen VK_OEM_1, aber ich weiß nicht, wie da zwischen ; und : hin und her schaltet.

Thx
Mordilion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 96

WinXP Prof., Win2k Prof.
Delphi 7 Prof., Delphi 2009 Prof., PHP4/5, CSS, HTML
BeitragVerfasst: Do 19.10.06 12:37 
Wie wäre es anstelle des VIRTUAL_KEYS einfach Ord(':') zu verwenden?


Gruß
Mordi

_________________
Für das große Chaos haben wir Computer. Die übrigen Fehler machen wir von Hand.
Der Mensch ist das wichtigste und kostbarste Peripheriegerät einer Computeranlage.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 19.10.06 19:48 
Hallo,
user profile iconPaddii hat folgendes geschrieben:

In der Liste für die virtual keys steht was von wegen VK_OEM_1, aber ich weiß nicht, wie da zwischen ; und : hin und her schaltet.
das bezieht sich auf eine US-Standard-Tastatur.
Zitat:
Used for miscellaneous characters; it can vary by keyboard.
Windows 2000/XP: For the US standard keyboard, the ';:' key

Für den Punkt findest du:
Zitat:
VK_OEM_PERIOD (BE)
Windows 2000/XP: For any country/region, the '.' key
dazu noch VK_Shift dann hast Du Deinen Doppelpunkt, im Code sieht es dann so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
Keybd_Event(VK_Shift,0,0,0);
Keybd_Event($BE,0,0,0);
Keybd_Event($BE,0,KEYEVENTF_KEYUP,0);
Keybd_Event(VK_Shift,0,KEYEVENTF_KEYUP,0);

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
KleinesProgramm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Do 20.03.08 09:42 
kann mir jmd den quelltext mit dem MyKeyEvent schritt für schritt erklären?? *leicht schäm* ich steig da nicht mehr durch...

und mich würde auch interessieren ob mykeyevent iein object im form braucht... danke für eure antworteN!
KleinesProgramm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Fr 21.03.08 19:55 
zu den VirtualKeys nochma:

diese liste msdn2.microsoft.com/...ibrary/ms645540.aspx versteh ich nicht ganz, das beispiel mit shift hat gut funktionert aber wie kann cih ein a machen z.B?

als ich (0x41) eingefügt hab kam ne fehler meldung, das nicht "x41" sondern ")" erwartet/verlangt wird!

kann mir des einer erklären pls?