473,396 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How To Detect Shift+Arrow Key

/*
I override IsInputKey() to direct the Arrow Keys (Cursor Keys) to my
custom System.Windows.Forms.Control. But, holding down the Shift-Key
prevents the Arrow Keys from coming through.

How can I intercept the Arrow Keys when holding down the Shift Key?
*/

//class KeyTest
class KeyTest:System.Windows.Forms.Control
{
//constructor
KeyTest()
{
KeyDown+=OnKeyDown;
Paint+=OnPaint;
Dock=System.Windows.Forms.DockStyle.Fill;
}
//IsInputKey
protected override bool IsInputKey(System.Windows.Forms.Keys a)
{
return
(a==System.Windows.Forms.Keys.Down)||
(a==System.Windows.Forms.Keys.Left)||
(a==System.Windows.Forms.Keys.Right)||
(a==System.Windows.Forms.Keys.Up)
?
true
:
base.IsInputKey(a);
}
//OnKeyDown
void OnKeyDown(object a,System.Windows.Forms.KeyEventArgs b)
{
switch(b.KeyCode)
{
case System.Windows.Forms.Keys.Left:
System.Console.Beep();
break;
case System.Windows.Forms.Keys.Right:
System.Console.Beep();
break;
case System.Windows.Forms.Keys.Up:
System.Console.Beep();
break;
case System.Windows.Forms.Keys.Down:
System.Console.Beep();
break;
case System.Windows.Forms.Keys.Escape:
System.Windows.Forms.Application.Exit();
break;
}
}
//OnPaint
void OnPaint(object a,System.Windows.Forms.PaintEventArgs b)
{
b.Graphics.DrawString
(
"Press an Arrow Key to hear a Beep. "+
"Hold down the Shift Key and the Arrow Keys no longer Beep. "+
"How can I solve this?"+
"\n\nPress <Escto quit...",
new System.Drawing.Font
(
"Times New Roman",
26,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Pixel
),
System.Drawing.Brushes.Black,
new System.Drawing.Rectangle
(
new System.Drawing.Point(0,0),
new System.Drawing.Size(Width,Height)
)
);
}
//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Form form=new System.Windows.Forms.Form();
form.Text="Shift+Arrow Keys";
form.Controls.Add(new KeyTest());
System.Windows.Forms.Application.Run(form);
}
}


Nov 1 '06 #1
0 2899

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Paul Nathan | last post by:
While trying to write a simple game which uses the arrow keys, I noticed that under the subroutine that handles mybase.keydown, everytime I pressed any arrow keys, or in fact any of the 9 keys...
5
by: skipc | last post by:
Hi, I am stuck... I've got a popup window that displays a list in table format with links on the bottom to navigate the list <prev> 1 2 3 ... <next> When I demo'd to the users... they...
0
by: Crirus | last post by:
I need to know how can I use Shift Arrow key , please. Regards, Crirus
1
by: perse981 | last post by:
Hi I need to know how, if even possible, to enable the user of my program to control the Size and Posisiton of the circle I have Drawn on the form by using the Enter Key (to increase size), Shift...
4
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually,...
9
by: Anish G | last post by:
Hi, I have a visual basic application which needs to detect keyboard events. I want to it to detect all the arrow keys (Left, Right, Up, Down) and these should be detected at form level. I have...
2
by: Robert Dufour | last post by:
In Vs 2005 Vb.Net How do you detcet the arrow keys, the function keys, the Ctrl Key, The shift key, the PrintScreen key, scroll lock key NumLock key. I know how to detect the keys that return ascii...
2
by: Charles Law | last post by:
I'll kick myself when you tell me, but ... I have a user control on a form, and I want the user control to see the arrow keys when I press them. If I press just about any other key the control's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.