Trying for the life of me to figure this out, but I can't seem to make sense of it.
I found some code that demonstrates how keyboard events are handled, but it doesn't work when I have a textbox on my form. When the textbox has focus, the event does not trigger. However, the only other code I found online will make events trigger even when the program itself has no focus. I don't want that. I just want it to work no matter where I hit the buttons in the form.
Basically, I want to be able to be able to make standard keyboard shortcuts like CTRL+O to open a file.
This is what I have now:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.KeyUp += new KeyEventHandler(Form1_KeyUp);
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString(), "Your input");
}
}
}