Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version

A Simple C# Global Low Level Keyboard Hook

, 30 May 2007 CPOL
A simple description and sample of creating a global low level keyboard hook in C#
key preview
key preview
key preview
key preview.exe
key preview.pdb
key preview.vshost.exe
key preview.suo
key preview.exe
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Utilities;

namespace key_preview {
	public partial class Form1 : Form {
		globalKeyboardHook gkh = new globalKeyboardHook();

		public Form1() {

		private void Form1_Load(object sender, EventArgs e) {
			gkh.KeyDown += new KeyEventHandler(gkh_KeyDown);
			gkh.KeyUp += new KeyEventHandler(gkh_KeyUp);

		void gkh_KeyUp(object sender, KeyEventArgs e) {
			lstLog.Items.Add("Up\t" + e.KeyCode.ToString());
			e.Handled = true;

		void gkh_KeyDown(object sender, KeyEventArgs e) {
			lstLog.Items.Add("Down\t" + e.KeyCode.ToString());
			e.Handled = true;

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.


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


About the Author

Software Developer
United States United States
I currently work as a Software Engineer for a company in North Carolina, mainly working with C#.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 30 May 2007
Article Copyright 2007 by StormySpike
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid