Jump to content

C# Checking if keyboard keys are pressed

AC-3

Hi.

I'm making an application where I want a Messagebox to popup when a certain key combanation is pressed on the keyboard. I've looked so long and tried many things, but I simply can't do it. 

I've found things on the internet, but nothing have worked. I want people to press Ctrl + Shift + "P".

Any help? I simply can't figure it out... I'm using a Windows.Form in C#

Link to comment
Share on other sites

Link to post
Share on other sites

Google for GlobalHook library it's written in C++ but you can still add it to the project

added benefit is that you can capture the keys globally even if your application is running in the background or as a service

 

Additionally you can use AutoHotKeys that writes some temp file on your disk and make your program check for the file constantly - be creative

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

41 minutes ago, DXMember said:

Google for GlobalHook library it's written in C++ but you can still add it to the project

added benefit is that you can capture the keys globally even if your application is running in the background or as a service

 

Additionally you can use AutoHotKeys that writes some temp file on your disk and make your program check for the file constantly - be creative

I will look into this for future projects! Looks intresting

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Oliver24x said:

Error    1    The name 'e' does not exist in the current context. How would I fix this? 

It sounds like the method doesn't have the correct parameters. It should look something like this.

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    // ...
}

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, madknight3 said:

It sounds like the method doesn't have the correct parameters. It should look something like this.


private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    //DoSomething();
}

 

 

Many thanks for helping a newbie! :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×