AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Wie sende ich tastaturanschläge?
Thema durchsuchen
Ansicht
Themen-Optionen

Wie sende ich tastaturanschläge?

Ein Thema von Rockett · begonnen am 4. Sep 2003 · letzter Beitrag vom 6. Sep 2003
Antwort Antwort
Rockett

Registriert seit: 4. Sep 2003
8 Beiträge
 
#1

Wie sende ich tastaturanschläge?

  Alt 4. Sep 2003, 19:20
hi ich bin noch eher neu in der delphi weld^^ und würde gerne
wissen wie ich tastaturanschläge an windows 2000pro sende
und fals es da unterschiede gibt auch in 98se

danke schonmal
  Mit Zitat antworten Zitat
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#2

Re: Wie sende ich tastaturanschläge?

  Alt 4. Sep 2003, 19:40
mouse_event
keybd_event

Code:
The mouse_event function synthesizes mouse motion and button clicks.

VOID mouse_event(

    DWORD dwFlags,   // flags specifying various motion/click variants
    DWORD dx,   // horizontal mouse position or position change
    DWORD dy,   // vertical mouse position or position change
    DWORD dwData,   // amount of wheel movement
    DWORD dwExtraInfo    // 32 bits of application-defined information
   );   
 

Parameters

dwFlags

A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values:

Value   Meaning
MOUSEEVENTF_ABSOLUTE   Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
MOUSEEVENTF_MOVE   Specifies that movement occurred.
MOUSEEVENTF_LEFTDOWN   Specifies that the left button changed to down.
MOUSEEVENTF_LEFTUP   Specifies that the left button changed to up.
MOUSEEVENTF_RIGHTDOWN   Specifies that the right button changed to down.
MOUSEEVENTF_RIGHTUP   Specifies that the right button changed to up.
MOUSEEVENTF_MIDDLEDOWN   Specifies that the middle button changed to down.
MOUSEEVENTF_MIDDLEUP   Specifies that the middle button changed to up.
MOUSEEVENTF_WHEEL   Windows NT only: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData
 

The flag bits that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.

dx

Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual x-coordinate; relative data is given as the number of mickeys moved.

dy

Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual y-coordinate; relative data is given as the number of mickeys moved.

dwData

If dwFlags is MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero.

dwExtraInfo

Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.

 

Return Values

This function has no return value.

Remarks

If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is given as absolute or relative integer values.
If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.

If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).
Relative mouse motion is subject to the effects of the mouse speed and the two mouse threshold values. In Windows NT, an end user sets these three values with the Mouse Tracking Speed slider of Control Panel's Mouse option; in Windows 95, an end user sets them with the Pointer Speed slider of the Control Panel's Mouse property sheet. An application obtains and sets these values with the SystemParametersInfo function.

The operating system applies two tests to the specified relative mouse motion. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the operating system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x or y axis by up to four times.

The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information.

See Also

GetMessageExtraInfo, SystemParametersInfo
Code:
The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.

VOID keybd_event(

    BYTE bVk,   // virtual-key code
    BYTE bScan,   // hardware scan code
    DWORD dwFlags,   // flags specifying various function options
    DWORD dwExtraInfo    // additional data associated with keystroke
   );   
 

Parameters

bVk

Specifies a virtual-key code. The code must be a value in the range 1 to 254.

bScan

Specifies a hardware scan code for the key.

dwFlags

A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags:

Value   Meaning
KEYEVENTF_EXTENDEDKEY   If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP   If specified, the key is being released. If not specified, the key is being depressed.
 

dwExtraInfo

Specifies an additional 32-bit value associated with the key stroke.

 

Return Values

This function has no return value.

Remarks

Although keybd_event passes an OEM-dependent hardware scan code to Windows, applications should not use the scan code. Windows converts scan codes to virtual-key codes internally and clears the up/down bit in the scan code before passing it to applications.
An application can simulate a press of the PRINTSCREEN key in order to obtain a screen snapshot and save it to the Windows clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT, and the bScan parameter set to 0 for a snapshot of the full screen or set bScan to 1 for a snapshot of the active window.

See Also

GetAsyncKeyState, GetKeyState, MapVirtualKey, SetKeyboardState
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Rockett

Registriert seit: 4. Sep 2003
8 Beiträge
 
#3

Re: Wie sende ich tastaturanschläge?

  Alt 4. Sep 2003, 19:53
Ich dank dir sehr.. werde es gleich testen...


mfg
Rockett Sword
  Mit Zitat antworten Zitat
Robert Marquardt
(Gast)

n/a Beiträge
 
#4

Re: Wie sende ich tastaturanschläge?

  Alt 5. Sep 2003, 13:17
Unter Win 98 ignoriert DirectInput mit keybd_event gesendete Daten. mouse_event funktioniert.
  Mit Zitat antworten Zitat
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#5

Re: Wie sende ich tastaturanschläge?

  Alt 5. Sep 2003, 16:30
dann zieh dir mal das 98er SDK rein, und schau unter "Group" von keybd_event nach, was´die schlaues schreiben!
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Robert Marquardt
(Gast)

n/a Beiträge
 
#6

Re: Wie sende ich tastaturanschläge?

  Alt 6. Sep 2003, 05:38
Die Info finde ich gerade nicht.
  Mit Zitat antworten Zitat
Rumpi

Registriert seit: 26. Aug 2003
Ort: Berlin
72 Beiträge
 
#7

Re: Wie sende ich tastaturanschläge?

  Alt 6. Sep 2003, 08:23
Hi,

versuchs mal damit

Delphi-Quellcode:
const
  KEYEVENTF_KEYDOWNUP = $FF;

function ForceForegroundWindow(hwnd: THandle): Boolean;
const
  SPI_GETFOREGROUNDLOCKTIMEOUT = $2000;
  SPI_SETFOREGROUNDLOCKTIMEOUT = $2001;
var
  ForegroundThreadID: DWORD;
  ThisThreadID: DWORD;
  timeout: DWORD;
begin
  if IsIconic(hwnd) then ShowWindow(hwnd, SW_RESTORE);

  if GetForegroundWindow = hwnd then Result := True
  else
  begin
    // Windows 98/2000 doesn't want to foreground a window when some other
    // window has keyboard focus

    if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion > 4)) or
      ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and
      ((Win32MajorVersion > 4) or ((Win32MajorVersion = 4) and
      (Win32MinorVersion > 0)))) then
    begin
      // Code from Karl E. Peterson, [url]www.mvps.org/vb/sample.htm[/url]
      // Converted to Delphi by Ray Lischner
      // Published in The Delphi Magazine 55, page 16

      Result := False;
      ForegroundThreadID := GetWindowThreadProcessID(GetForegroundWindow, nil);
      ThisThreadID := GetWindowThreadPRocessId(hwnd, nil);
      if AttachThreadInput(ThisThreadID, ForegroundThreadID, True) then
      begin
        BringWindowToTop(hwnd); // IE 5.5 related hack
        SetForegroundWindow(hwnd);
        AttachThreadInput(ThisThreadID, ForegroundThreadID, False);
        Result := (GetForegroundWindow = hwnd);
      end;
      if not Result then
      begin
        // Code by Daniel P. Stasinski
        SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, @timeout, 0);
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(0),
          SPIF_SENDCHANGE);
        BringWindowToTop(hwnd); // IE 5.5 related hack
        SetForegroundWindow(hWnd);
        SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, TObject(timeout), SPIF_SENDCHANGE);
      end;
    end
    else
    begin
      BringWindowToTop(hwnd); // IE 5.5 related hack
      SetForegroundWindow(hwnd);
    end;

    Result := (GetForegroundWindow = hwnd);
  end;
end;


procedure SimulateKeystroke( bVK, bScan : byte; wFlags, wExtraInfo : DWORD);
const
  KEYEVENTF_KEYDOWN = 0; //KEYEVENTF_KEYUP = 2; // windows.pas
var
  ExtraInfo : Word;
begin
  //bScan := Lo(MapVirtualKey(bVK,0));
  if wExtraInfo = KEYEVENTF_KEYDOWNUP then
  begin
    ExtraInfo := 0;
    keybd_event(bVK, bScan, KEYEVENTF_KEYDOWN, ExtraInfo);
    keybd_event(bVK, bScan, KEYEVENTF_KEYUP , ExtraInfo);
  end
  else
    keybd_event(bVK, bScan, wFlags, wExtraInfo);
end;

procedure SendKeyTo( ClassName: String; bVK: Byte);
var
  hWnd, hSavedWnd : hWnd;
begin
  hWnd:= FindWindowEx( 0,0,PChar( ClassName ), nil );
  if Not (hWnd <> 0) then
    exit;

  hSavedWnd := GetForeGroundWindow;
  //SetForegroundWindow( hWnd );
  ForceForegroundWindow( hWnd );
  Application.ProcessMessages;
  try
    SimulateKeystroke( bVK, 0, 0, KEYEVENTF_KEYDOWNUP );
  finally
    Application.ProcessMessages;
    //SetForegroundWindow( hSavedWnd );
    ForceForegroundWindow( hSavedWnd );
  end;
end;

... SendKeyTo( '????', VK_Right );
Suche im Forum nach
SetForegroundWindow oder ForceForegroundWindow

Ich habe noch schnell den code von
ForceForegroundWindow dazu kopiert

mfg Rumpi und Pascal
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz