473,783 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.C ontrol
{
//constructor
KeyTest()
{
KeyDown+=OnKeyD own;
Paint+=OnPaint;
Dock=System.Win dows.Forms.Dock Style.Fill;
}
//IsInputKey
protected override bool IsInputKey(Syst em.Windows.Form s.Keys a)
{
return
(a==System.Wind ows.Forms.Keys. Down)||
(a==System.Wind ows.Forms.Keys. Left)||
(a==System.Wind ows.Forms.Keys. Right)||
(a==System.Wind ows.Forms.Keys. Up)
?
true
:
base.IsInputKey (a);
}
//OnKeyDown
void OnKeyDown(objec t a,System.Window s.Forms.KeyEven tArgs b)
{
switch(b.KeyCod e)
{
case System.Windows. Forms.Keys.Left :
System.Console. Beep();
break;
case System.Windows. Forms.Keys.Righ t:
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.Esca pe:
System.Windows. Forms.Applicati on.Exit();
break;
}
}
//OnPaint
void OnPaint(object a,System.Window s.Forms.PaintEv entArgs b)
{
b.Graphics.Draw String
(
"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.Regul ar,
System.Drawing. GraphicsUnit.Pi xel
),
System.Drawing. Brushes.Black,
new System.Drawing. Rectangle
(
new System.Drawing. Point(0,0),
new System.Drawing. Size(Width,Heig ht)
)
);
}
//Main
[System.STAThrea d]
static void Main()
{
System.Windows. Forms.Form form=new System.Windows. Forms.Form();
form.Text="Shif t+Arrow Keys";
form.Controls.A dd(new KeyTest());
System.Windows. Forms.Applicati on.Run(form);
}
}


Nov 1 '06 #1
0 2922

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

Similar topics

0
3266
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 above it (End, Del, PGDN etc) that the result for e.keycode was 'none', yet it still picked up my keypress! All other keys work fine. This problem only recently happened. I have tried the following to help: Roll back to D.X 9.0a and 9.0 SDK, remove...
5
18229
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 immediately asked if they could use the arrow keys and enter key to navigate the list. I think there must be a way to do this, but I can't figure it out.
0
1306
by: Crirus | last post by:
I need to know how can I use Shift Arrow key , please. Regards, Crirus
1
2029
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 Key (to decrease size), and Arrow Keys (to alter posistion of circle on screen). My program consists of a single form with six command buttons and a circle that I drew with the shape control. For each of the command buttons I have written a click...
4
3294
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, the control is meant to be a simple drawing program. To test it out I have put the control on a Windows form which also contains several buttons. I have added a KeyDown event handler to the custom control (see code below). It responds fine to keys...
9
11310
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 enabled Key Preview at form level. But not able to figure out how do I detect these keys once the form is loaded? Thanks!
2
7142
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 chararcters but these do not seem to. So how do youn detect when they have been pressed? Thanks for any help Bob
2
3324
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 KeyDown event is fired, but not when I press a direction key. I want to see them in the KeyDown event so that I can respond as soon as the key is depressed, and I want to detect when the key is held down so that I can perform an action...
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.