Laden...

Keylogger blockiert Tastatur

Erstellt von CrazyDeveloper vor 9 Jahren Letzter Beitrag vor 9 Jahren 1.542 Views
C
CrazyDeveloper Themenstarter:in
3 Beiträge seit 2015
vor 9 Jahren
Keylogger blockiert Tastatur

Hallo, ich bin ziehmlich neu in C#, auch erst 14 jahre jung, ich brauche eure hilfe, und nein das Programm soll kein bösartiger Keylogger werden, ich möchte nur ein Programm schreiben, zum lernen, heisst das Programm wird später keine verwendung haben

Also, ich habe den Keylogger fast fertig, nur das Problem ist, der Keylogger läuft im Hintergrund, soweit gut, nur wenn ich zum Bsp. google öffne und dort was suchen will und der Keylogger noch aktiv ist, kann ich nirgendswo schreiben, heisst die tastatureingaben werden komplett abgefangen, und eigentlich wollte ich es ja so haben, das das Programm im Hintergrund ist, aber ich trozdem noch schreiben kann, wundert euch bitte nicht über den Code, wie gesagt ich bin neu, und der Code ist bestimmt viel leichter zu schreiben aber naja, ich komme so besser damit klar


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        [DllImport("user32.dll")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);

        [DllImport("user32.dll")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        const int MOD_Null = 0x0000;
        const int MOD_SHIFT = 0x0004;
        const int WM_HOTKEY = 0x0312;


        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            RegisterHotKey(this.Handle, 1, MOD_Null, (int)Keys.A);
            RegisterHotKey(this.Handle, 2, MOD_Null, (int)Keys.B);
            RegisterHotKey(this.Handle, 3, MOD_Null, (int)Keys.C);
            RegisterHotKey(this.Handle, 4, MOD_Null, (int)Keys.D);
            RegisterHotKey(this.Handle, 5, MOD_Null, (int)Keys.E);
            RegisterHotKey(this.Handle, 6, MOD_Null, (int)Keys.F);
            RegisterHotKey(this.Handle, 7, MOD_Null, (int)Keys.G);
            RegisterHotKey(this.Handle, 8, MOD_Null, (int)Keys.H);
            RegisterHotKey(this.Handle, 9, MOD_Null, (int)Keys.I);
            RegisterHotKey(this.Handle, 10, MOD_Null, (int)Keys.J);
            RegisterHotKey(this.Handle, 11, MOD_Null, (int)Keys.K);
            RegisterHotKey(this.Handle, 12, MOD_Null, (int)Keys.L);
            RegisterHotKey(this.Handle, 13, MOD_Null, (int)Keys.M);
            RegisterHotKey(this.Handle, 14, MOD_Null, (int)Keys.N);
            RegisterHotKey(this.Handle, 15, MOD_Null, (int)Keys.O);
            RegisterHotKey(this.Handle, 16, MOD_Null, (int)Keys.P);
            RegisterHotKey(this.Handle, 17, MOD_Null, (int)Keys.Q);
            RegisterHotKey(this.Handle, 18, MOD_Null, (int)Keys.R);
            RegisterHotKey(this.Handle, 19, MOD_Null, (int)Keys.S);
            RegisterHotKey(this.Handle, 20, MOD_Null, (int)Keys.T);
            RegisterHotKey(this.Handle, 21, MOD_Null, (int)Keys.U);
            RegisterHotKey(this.Handle, 22, MOD_Null, (int)Keys.V);
            RegisterHotKey(this.Handle, 23, MOD_Null, (int)Keys.W);
            RegisterHotKey(this.Handle, 24, MOD_Null, (int)Keys.X);
            RegisterHotKey(this.Handle, 25, MOD_Null, (int)Keys.Y);
            RegisterHotKey(this.Handle, 26, MOD_Null, (int)Keys.Z);
            RegisterHotKey(this.Handle, 27, MOD_Null, (int)Keys.Space);
            textBox1.Visible = false;

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            UnregisterHotKey(this.Handle, 1);
        }
                protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 1)
                textBox1.AppendText("A");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 2)
                textBox1.AppendText("B");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 3)
                textBox1.AppendText("C");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 4)
                textBox1.AppendText("D");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 5)
                textBox1.AppendText("E");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 6)
                textBox1.AppendText("F");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 7)
                textBox1.AppendText("G");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 8)
                textBox1.AppendText("H");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 9)
                textBox1.AppendText("I");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 10)
                textBox1.AppendText("J");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 11)
                textBox1.AppendText("K");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 12)
                textBox1.AppendText("L");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 13)
                textBox1.AppendText("M");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 14)
                textBox1.AppendText("N");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 15)
                textBox1.AppendText("O");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 16)
                textBox1.AppendText("P");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 17)
                textBox1.AppendText("Q");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 18)
                textBox1.AppendText("R");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 19)
                textBox1.AppendText("S");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 20)
                textBox1.AppendText("T");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 21)
                textBox1.AppendText("U");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 22)
                textBox1.AppendText("V");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 23)
                textBox1.AppendText("W");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 24)
                textBox1.AppendText("X");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 25)
                textBox1.AppendText("Y");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 26)
                textBox1.AppendText("Z");
            if (m.Msg == WM_HOTKEY && (int)m.WParam == 27)
                textBox1.AppendText(" ");
            base.WndProc(ref m);
        }

                private void button1_Click(object sender, EventArgs e)
                {
                    string[] Zeilen = { textBox1.Text };
                    System.IO.File.WriteAllLines("c:\\Users\\Paule\\Desktop\\KeyLogger.txt", Zeilen);
                    Application.Exit();
                }

    }
}

Schlagwörter: <Keylogger, Tastatur blockiert>

H
523 Beiträge seit 2008
vor 9 Jahren

Du verwendest die falschen APIs. RegisterHotKey ist dafür da um systemweite Hotkeys für Deine Anwendung zu registrieren, aber nicht um alle Tastatureingaben zu überwachen, das realisiert man mit anderen API-Funktionen.

C
CrazyDeveloper Themenstarter:in
3 Beiträge seit 2015
vor 9 Jahren

Heisst, ich muss nochmal alles umschreiben oder wie soll ich das verstehen?
welche APIs sollte ich verwenden?

4.939 Beiträge seit 2008
vor 9 Jahren

Ja, das Stichwort dazu lautet: Keyboard (bzw. Mouse) Hooks

s. z.B.
Globale Hooks mit c# (nichtnur lowlevel)
KeyboardHook, MouseHook, WindowHook
[Sample] Globale Hooks in C#

Du solltest dich dann aber gut mit der WinAPI und C auskennen.
Ich hoffe mal wirklich, daß du das nur für dich zum Spaß programmierst und nicht um anderen eine Malware unterzuschieben...

C
CrazyDeveloper Themenstarter:in
3 Beiträge seit 2015
vor 9 Jahren

Danke 😃

nein ich programmiere es nur für mich, um dazu zu lernen 😃