Tasten sperren (Finde Thread nicht mehr :( )



  • Hallo,
    ich hatte einen Thread geöffnet den ich nicht mehr finde, weder per Suche mit "Autor", mit "*tasten* *sperren*" oder "*hhook*"

    Also ich möchte Tasten systemweit sperren.
    Mein Quelltest (aus dem Beispiel)

    unit1.cpp

    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TKeyHookForm *KeyHookForm;
    
    extern "C" __declspec(dllexport) __stdcall void SetHook(void);
    extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
    extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
    //---------------------------------------------------------------------------
    __fastcall TKeyHookForm::TKeyHookForm(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TKeyHookForm::KeyHook(TMessage &Message)
    {
      char Key[80];
      GetKeyNameText(Message.LParam, Key, 80);
      NULL;
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TKeyHookForm::Button2Click(TObject *Sender)
    {
    RemoveHook();
    Application->Terminate();
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TKeyHookForm::Button1Click(TObject *Sender)
    {
    SetHook();        
    }
    //---------------------------------------------------------------------------
    

    keydll.dll

    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #include <windows.h>
    #pragma hdrstop
    //---------------------------------------------------------------------------
    //---------------------------------------------------------------------------
    #define WM_KEYHOOK WM_USER+100
    HHOOK ghhookKB;
    HINSTANCE ghInst;
    #pragma argsused
    int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
    {
            ghInst = hinst;
            return 1;
    }
    //---------------------------------------------------------------------------
    extern "C" __declspec(dllexport) __stdcall void SetHook(void);
    extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
    extern "C" __declspec(dllexport) __stdcall DWORD CheckKey(int, WORD,LONG);
    //---------------------------------------------------------------------------
    void __stdcall SetHook(void)
    {
      HOOKPROC lpfnHookProc = NULL;
      lpfnHookProc = GetProcAddress(GetModuleHandle("keydll.dll"),"CheckKey");
      ghhookKB = SetWindowsHookEx(WH_KEYBOARD, lpfnHookProc, ghInst, NULL);
    }
    //---------------------------------------------------------------------------
    void __stdcall RemoveHook(void)
    {
      UnhookWindowsHookEx(ghhookKB);
    }
    //---------------------------------------------------------------------------
    DWORD __stdcall CheckKey(int nCode, WORD wParam, LONG lParam)
    {
      HWND ghAppWnd = FindWindow("TKeyHookForm", 0);
      if((nCode < 0) || nCode == HC_NOREMOVE)
        return CallNextHookEx(ghhookKB, nCode, wParam, lParam);
    
      // Skip if it's a repeat
      if(lParam & 0x40000000)
        return CallNextHookEx(ghhookKB, nCode, wParam, lParam);
    
      // Send key information to the main window
      SendMessage(ghAppWnd, WM_KEYHOOK, 0, lParam);
    
      return CallNextHookEx(ghhookKB, nCode, wParam, lParam);
    }
    //---------------------------------------------------------------------------
    
    unit1.h
    [cpp]
    //---------------------------------------------------------------------------
    
    #ifndef Unit1H
    #define Unit1H
    #define WM_KEYHOOK WM_USER+100 
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TKeyHookForm : public TForm
    {
    __published:    // Von der IDE verwaltete Komponenten
            TButton *Button1;
            TButton *Button2;
            TLabel *Label1;
            TLabel *Label2;
            void __fastcall Label1Click(TObject *Sender);
            void __fastcall Button2Click(TObject *Sender);
            void __fastcall Button1Click(TObject *Sender);
    private: // User declarations
      MESSAGE void __fastcall KeyHook(TMessage &Message);
        BEGIN_MESSAGE_MAP
          MESSAGE_HANDLER(WM_KEYHOOK, TMessage, KeyHook);
        END_MESSAGE_MAP(TForm);
    public:     // Anwender-Deklarationen 
            __fastcall TKeyHookForm(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TKeyHookForm *KeyHookForm;
    //---------------------------------------------------------------------------
    #endif
    

    [/cpp]



  • Sorry,

    jedenfalls weiß ich nicht wie genau ich das jetzt machen soll, das die Tasten systemweit nicht mehr funktionieren.

    Danke im Voraus



  • Weiß keiner? ^^



  • ich könnte mir durchaus vorstellen, das einige hier soetwas können, doch diese werden auf soetwas kaum antworten.

    eventuell ist es mit hooks möglich, aber damit habe ich mich noch kaum beschäfftigt.



  • Naja ist doch ein KeyBoard Hook so nennt man es glaub ich.
    Aber ich glaub man muss nur was in TKeyHookForm::KeyHook schreiben damit das funktioniert.

    Wieso sollten die die davon Ahnung haben nicht darauf antworten? Habe ich etwas faölsch gemacht? 😮 😕


Anmelden zum Antworten