| | |
Problem with keyboard control in C#
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2008
Posts: 107
Reputation:
Solved Threads: 5
Hello,
Recently I needed to assign keyboard control to my program; so and I searched the Internet, I found many examples but it seems all have one little problem(or it's my mistake?):
I use this test code:
Keyboard control works fine but not for all key: Enter, Up, Down, Right, Left -> these are not working.
. I don't understand why, because these controls are defined in c# like the others. If you have an idea, please post it. Thanks
Recently I needed to assign keyboard control to my program; so and I searched the Internet, I found many examples but it seems all have one little problem(or it's my mistake?):
I use this test code:
C# Syntax (Toggle Plain Text)
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 myheys { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.KeyUp += new KeyEventHandler(button1_KeyDown); } private void button1_KeyDown(object sender, KeyEventArgs e) { switch ((int)e.KeyValue) { case (int)Keys.Space: MessageBox.Show("SPACE"); break; case (int)Keys.Escape: MessageBox.Show("ESC"); break; case (int)Keys.Enter: MessageBox.Show("ENTER"); break; case (int)Keys.Delete: MessageBox.Show("del"); break; case (int)Keys.Up: MessageBox.Show("up"); break; case (int)Keys.Down: MessageBox.Show("down"); break; case (int)Keys.Left: MessageBox.Show("left"); break; case (int)Keys.Right: MessageBox.Show("right"); break; case (int)Keys.F10: MessageBox.Show("F10"); break; case (int)Keys.F: MessageBox.Show("f"); break; } } } }
Keyboard control works fine but not for all key: Enter, Up, Down, Right, Left -> these are not working.
. I don't understand why, because these controls are defined in c# like the others. If you have an idea, please post it. Thanks
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
The button is eating your keys, if you remove the button the problem goes too If all you're using is the button to get the events setup, dont, use the forms direct.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
![]() |
Similar Threads
- Problem on using keyboard wedge Barcode scanner with VBA (Visual Basic 4 / 5 / 6)
- GE Wireless Keyboard & Mouse (USB Devices and other Peripherals)
- OS9.1 to OSX.2 Problem (Apple Hardware)
- keybord problems (OS X)
- Another problem with BRIDGE.DLL (Viruses, Spyware and other Nasties)
- CommonNames problem (Web Browsers)
Other Threads in the C# Forum
- Previous Thread: have a problem with inheritance
- Next Thread: Create a login page for a URL
Views: 1777 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access algorithm array barchart bitmap box button buttons c# chat check checkbox class client code color combobox control conversion csharp custom database datagridview dataset datetime degrees draganddrop drawing encryption enum excel file files form format forms ftp function gcd gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






