Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / Win32

Minimal Key Logger Using RAWINPUT

Rate me:
Please Sign up or sign in to vote.
4.71/5 (7 votes)
8 Mar 2013CPOL5 min read 38.6K   2.6K   18  
This is a VB.NET and C# version of "Minimal Key Logger Using RAWINPUT".
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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private RawInputHook InputHook;

        public void InputFromKeyboard(RAWINPUTHEADER riHeader, RAWKEYBOARD riKeyboard)
        {
            string s = "";
            s = s + "MCode: 0x" + riKeyboard.MakeCode.ToString("X4");
            s = s + "  VKey: 0x" + riKeyboard.VKey.ToString("X4");
            s = s + "  Mssg: 0x" + riKeyboard.Message.ToString("X4");
            s = s + "  Flag: 0x" + riKeyboard.Flags.ToString("X4");
            s = s + "   Rsrvd: 0x" + riKeyboard.Reserved.ToString("X4");
            s = s + "   ExInf: 0x" + riKeyboard.ExtraInformation.ToString("X4");
            s = s + "  Devc: 0x" + riHeader.hDevice.ToString("X4");
            s = s + "   .Size: 0x" + riHeader.dwSize.ToString("X4");
            s = s + "   .Type: 0x" + riHeader.dwType.ToString("X4");
            s = s + "   wPara: 0x" + riHeader.wParam.ToString("X4");
            s = s + "\r\n";
            System.Diagnostics.Debug.Write(s);
            this.textBox1.Text += s;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            InputHook = new RawInputHook();
            InputHook.OnRawInputFromKeyboard += InputFromKeyboard;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions