AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Programm mit gedrückter Shift-Taste starten

Ein Thema von Popov · begonnen am 7. Mär 2015 · letzter Beitrag vom 7. Mär 2015
 
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#6

AW: Programm mit gedrückter Shift-Taste starten

  Alt 7. Mär 2015, 13:18
Ich weiß, ist primitiv, aber funzt. SirRufo würde hierfür vermutlich eine Klasse basteln. (@SirRufo: ist jetzt nicht bös gemeint!) Wäre programmiertechnisch auch sinnvoller, keine Frage, aber das ist mir in diesem Fall ehrlich gesagt so was von...
Schon ok, aber ja, ich würde das in eine Klasse (Struktur) packen, die dann den Zugriff vereinfacht.
Delphi-Quellcode:
unit KeyStateSnapshot;

interface

uses
  Winapi.Windows;

type
  TKeyState = ( ksPressed, ksToggled );
  TKeyStates = set of TKeyState;

  IKeyStateSnapshot = interface
    ['{83675AEC-1F42-44CD-84F3-0B7EED2EE186}']
    function GetKeyStates( Key: Byte ): TKeyStates;
    property KeyStates[Key: Byte]: TKeyStates read GetKeyStates; default;
  end;

  TKeyStateSnapshot = class( TInterfacedObject, IKeyStateSnapshot )
  private const
    BITMASK_KEY_ISPRESSED = $80;
    BITMASK_KEY_ISTOGGLED = $01;
  private
    class var _Startup: IKeyStateSnapshot;
    class constructor Create;
  private
    FKeyboardState: TKeyboardState;
    function GetKeyStates( Key: Byte ): TKeyStates;
  protected
    constructor Create;
  public
    class function Current: IKeyStateSnapshot;
    class function Startup: IKeyStateSnapshot;
  end;

implementation

{ TKeyStateSnapshot }

class constructor TKeyStateSnapshot.Create;
begin
  _Startup := TKeyStateSnapshot.Create;
end;

constructor TKeyStateSnapshot.Create;
var
  LResult: LongBool;
begin
  inherited Create;
  LResult := GetKeyboardState( FKeyboardState );
end;

class function TKeyStateSnapshot.Current: IKeyStateSnapshot;
begin
  Result := TKeyStateSnapshot.Create;
end;

function TKeyStateSnapshot.GetKeyStates( Key: Byte ): TKeyStates;
var
  LState: Byte;
begin
  Result := [];
  LState := FKeyboardState[Key];
  if ( LState and BITMASK_KEY_ISPRESSED ) = BITMASK_KEY_ISPRESSED
  then
    Result := Result + [ksPressed];
  if ( LState and BITMASK_KEY_ISTOGGLED ) = BITMASK_KEY_ISTOGGLED
  then
    Result := Result + [ksToggled];
end;

class function TKeyStateSnapshot.Startup: IKeyStateSnapshot;
begin
  Result := _Startup;
end;

end.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat
 


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 18:23 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz