AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Probleme mit Sendkey nach Umstieg auf Win764Bit
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit Sendkey nach Umstieg auf Win764Bit

Ein Thema von Bomberbb · begonnen am 3. Mär 2010 · letzter Beitrag vom 3. Mär 2010
Antwort Antwort
Seite 1 von 2  1 2      
Bomberbb

Registriert seit: 23. Sep 2003
227 Beiträge
 
#1

Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 08:59
Hallo,

ich hab ein Programm seit einem Jahr im Einsatz, welches die Überwachten Ausdrücke von Delphi in eine Textdatei speichert. Nun, nach dem Umstieg von WinXP32Bit auf
Win764Bit funktioniert es nicht mehr. Ich habe im Programm eine Funktion aus dem Netz genutzt, die jetzt anscheinend die Probleme macht. Normale Tastendrücke wie z.B.
VK-DOWN funktionieren. Was nicht mehr funktioniert ist alles in Verbindung mit [ssCtrl]. Ich hab aber nun keine Ahnung, warum das unter 64Bit plötzlich nicht mehr funktionieren sollte...

Delphi-Quellcode:
procedure PostKeyExHWND(hWindow: HWnd; key: Word; const shift: TShiftState;
  specialkey: Boolean);
{************************************************************
* Procedure PostKeyEx
*
* Parameters:
*  hWindow: target window to be send the keystroke
*  key    : virtual keycode of the key to send. For printable
*          keys this is simply the ANSI code (Ord(character)).
*  shift  : state of the modifier keys. This is a set, so you
*          can set several of these keys (shift, control, alt,
*          mouse buttons) in tandem. The TShiftState type is
*          declared in the Classes Unit.
*  specialkey: normally this should be False. Set it to True to
*          specify a key on the numeric keypad, for example.
*          If this parameter is true, bit 24 of the lparam for
*          the posted WM_KEY* messages will be set.
* Description:
*  This procedure sets up Windows key state array to correctly
*  reflect the requested pattern of modifier keys and then posts
*  a WM_KEYDOWN/WM_KEYUP message pair to the target window. Then
*  Application.ProcessMessages is called to process the messages
*  before the keyboard state is restored.
* Error Conditions:
*  May fail due to lack of memory for the two key state buffers.
*  Will raise an exception in this case.
* NOTE:
*  Setting the keyboard state will not work across applications
*  running in different memory spaces on Win32 unless AttachThreadInput
*  is used to connect to the target thread first.
*Created: 02/21/96 16:39:00 by P. Below
************************************************************}

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 }
Gut, es gibt zwar noch die Möglichkeit mit keybd_event zu arbeiten, aber eigendlich möchte ich den Tastendruck explizit an ein Fenster senden.

Kann jemand weiterhelfen?

Gruß

BBB
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.139 Beiträge
 
Delphi 12 Athens
 
#2

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 09:22
Mit welchen Rechten läuft deine IDE?

Ein Nicht-Admin-Prozess kann nicht mit einem Admin-Prozess komminizieren.
(man hat nur noch auf anndere Prozesse mit gleichwertigen oder weniger Rechten Zugriff)
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Bomberbb

Registriert seit: 23. Sep 2003
227 Beiträge
 
#3

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 09:36
Es sind beide Progs von mir gestartet. Ich hab Administratorrechte. Habe beide Progsauch nicht mit der Option "Als Administrator ausführen" gestartet.

Das seltsame ist zudem, dass das Senden normaler Tastendrücke ja funktioniert...
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.008 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#4

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 11:39
Handelt es sich um eine 64bit App, an die du die Messages schickst?
Dann musst du evtl einige Dinge beachten.
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.139 Beiträge
 
Delphi 12 Athens
 
#5

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 11:43
Zitat:
ich hab ein Programm seit einem Jahr im Einsatz, welches die Überwachten Ausdrücke von Delphi in eine Textdatei speichert.
Die Delphi-IDE und 64 Bit?
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.008 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#6

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 11:49
Zitat von himitsu:
Zitat:
ich hab ein Programm seit einem Jahr im Einsatz, welches die Überwachten Ausdrücke von Delphi in eine Textdatei speichert.
Die Delphi-IDE und 64 Bit?
Aus diesem Satz konnte ich persönlich nicht schließen, dass er ausdrücklich nur an die Delphi IDE Messages schickt.
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.139 Beiträge
 
Delphi 12 Athens
 
#7

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 11:54
Dieses oder ein ähnliches Programm schwirrt irgendwo in der DP rum ... vielleicht hatte ich beim Verstehen daher einen Vorteil, weil ich dieses/sowas schonmal gesehn hab.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Bomberbb

Registriert seit: 23. Sep 2003
227 Beiträge
 
#8

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 13:40
Also, es handelt sich um die Lieste der überwachten Ausdrücke in Delphi 5. An dieses Fenster schicke ich die Botschaften. Und das ganze passiert von einem in Delphi geschriebenen Programm. Sollte also beides 32 Bit sein.
Das Dumme ist, dass ich auch gar nicht checken kann, was in dem Fenster ankommt...
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.139 Beiträge
 
Delphi 12 Athens
 
#9

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 14:28
versuch es mal so
Delphi-Quellcode:
procedure SendKeyEx(hWindow: HWnd; key: Word;
  const shift: TShiftState; specialkey: Boolean);
{************************************************************
* Procedure SendKeyEx
*
* Parameters:
*  hWindow: target window to be send the keystroke
*  key    : virtual keycode of the key to send. For printable
*          keys this is simply the ANSI code (Ord(character)).
*  shift  : state of the modifier keys. This is a set, so you
*          can set several of these keys (shift, control, alt,
*          mouse buttons) in tandem. The TShiftState type is
*          declared in the Classes Unit.
*  specialkey: normally this should be False. Set it to True to
*          specify a key on the numeric keypad, for example.
*          If this parameter is true, bit 24 of the lparam for
*          the posted WM_KEY* messages will be set.
* Description:
*  This procedure sets up Windows key state array to correctly
*  reflect the requested pattern of modifier keys and then posts
*  a WM_KEYDOWN/WM_KEYUP message pair to the target window. Then
*  Application.ProcessMessages is called to process the messages
*  before the keyboard state is restored.
* Error Conditions:
*  May fail due to lack of memory for the two key state buffers.
*  Will raise an exception in this case.
* NOTE:
*  Setting the keyboard state will not work across applications
*  running in different memory spaces on Win32 unless AttachThreadInput
*  is used to connect to the target thread first.
*Created: 02/21/96 16:39:00 by P. Below
************************************************************}

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
        if not PostMessage(hWindow, WM_SYSKEYDOWN, key, lParam)
            or not PostMessage(hWindow, WM_SYSKEYUP, key, lParam or $C0000000) then
          raise Exception.Create(SysErrorMessage(GetLastError));
      end
      else
      begin
        if not PostMessage(hWindow, WM_KEYDOWN, key, lParam)
            or not PostMessage(hWindow, WM_KEYUP, key, lParam or $C0000000) then
          raise Exception.Create(SysErrorMessage(GetLastError));
      end;

      (* restore the old key state map *)
      SetKeyboardState(pKeyBuffers^[1]);
    finally
      (* free the memory for the key state buffers *)
      Dispose(pKeyBuffers);
    end; { If }
  end;
end; { PostKeyEx }
Es wird nicht umsonst ständig gesagt, daß man gefälligst mal die Rückgabewerte prüfen soll ... vorallem wenn etwas nicht geht und man weiß nicht warum.

Wobei man es auch mal über SendMessage/SendMessageTimeout anstatt über PostMessage versuchen könnte,
dann würde man auch noch den Rückgabewert des Programms erfahren.


MSDN: PostMessage
Microsoft Windows Vista and later. Message posting is subject to User Interface Privilege Isolation (UIPI). The thread of a process can post messages only to message queues of threads in processes of lesser or equal integrity level.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Bomberbb

Registriert seit: 23. Sep 2003
227 Beiträge
 
#10

Re: Probleme mit Sendkey nach Umstieg auf Win764Bit

  Alt 3. Mär 2010, 15:11
Wenn ich Deinen Quelltext nehme, ist der Rückgabewert von Postmessage jeweils true.
Wenn ich Sendmessage verwende, ist der Rückgabewert 0.
Auch wenn ich das Programm als Administrator starte ändert sich das Verhalten leider nicht.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


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 19:58 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