473,396 Members | 1,722 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.

Cursor Keys

Hi,
I am trying to control the Cursor Keys(Left, Right, Up, Down) in a
Windows Form Application from the KeyPress Event.

Can someone give me some help how do I identify which key was pressed.
Thanks in Advance
Nov 17 '05 #1
6 7360
use the Keys enum?

"Xarky" <be*********@yahoo.com> schrieb im Newsbeitrag
news:bc*************************@posting.google.co m...
Hi,
I am trying to control the Cursor Keys(Left, Right, Up, Down) in a
Windows Form Application from the KeyPress Event.

Can someone give me some help how do I identify which key was pressed.
Thanks in Advance

Nov 17 '05 #2
Hi

I found out Keys.Up, Keys.Left...etc

From the KeyPress EventHandler, I am using e.KeyChar

When comparing (e.KeyChar == Key.Left), a compile time error is given.

Operator '==' cannot be applied to operands of type 'char' and
'System.Windows.Forms.Keys'

How should I do it?

Thanks for your help
*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
since e.KeyChar is an char you have to cast it to Keys first.
"xarky d_best" <be*********@yahoo.com> schrieb im Newsbeitrag
news:e0**************@TK2MSFTNGP15.phx.gbl...
Hi

I found out Keys.Up, Keys.Left...etc

From the KeyPress EventHandler, I am using e.KeyChar

When comparing (e.KeyChar == Key.Left), a compile time error is given.

Operator '==' cannot be applied to operands of type 'char' and
'System.Windows.Forms.Keys'

How should I do it?

Thanks for your help
*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #4
Hello

Try catching keys in key down or key up event.

Aleksandar

"xarky d_best" <be*********@yahoo.com> wrote in message
news:e0**************@TK2MSFTNGP15.phx.gbl...
Hi

I found out Keys.Up, Keys.Left...etc

From the KeyPress EventHandler, I am using e.KeyChar

When comparing (e.KeyChar == Key.Left), a compile time error is given.

Operator '==' cannot be applied to operands of type 'char' and
'System.Windows.Forms.Keys'

How should I do it?

Thanks for your help
*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #5
Hi,

I am doing as follows, in the event handler:

Keys key = (Keys)e.KeyChar;
if (key == Keys.Left)
MessageBox.Show("LEFT");

No messagebox is being given. I set a breakpoint on those lines, and
when I press the errors nothing is happening, but when I press any other
key(Example - a), I am entering in visual studio to debug.

It seems that the arrows keys are not being handled?

Can some further help be given.
Thanks in Advance

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #6
Hi,
I used the KeyDown Event handler, and it solved my problems
Thanks for your help!

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #7

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

Similar topics

4
by: Chris | last post by:
Since I've installed (from sources) Python 2.3.4 on SuSE 8.2 the command history is not working anymore. When I press the cursor keys I get ^[[A or ^[[B .... I also tried to install IPython but...
3
by: inevercheckthisaddress | last post by:
I'm writing some stuff where I wish to allow the cursor keys to control elements in a page. This has not been a problem except with Safari which appears to duplicate the keydown and keyup events...
14
by: xxbmichae1 | last post by:
I have a <select> object that i've set up an onchange event that fires in IE fine when I use the cursor up and down in the list, but If I use the cursor up and down in Firefox the event doesn't...
0
by: M | last post by:
Hi, I got a C# project which uses a "CORE" originally written in SDK. If I triger an event which bring up a Modeless dialog created using either old SDK C++ code or MFC/C++ code, the cursor keys...
2
by: Sagaert Johan | last post by:
Hi I have a usercontrol , the keypress and keyup/down events do not seem to work on the cursor keys . How can i capture the cursor keys when my control has the focus ? Johan
3
by: Simon Morgan | last post by:
Hi, I'm having trouble with the following code. The problem is that the value read by getch() when I hit the up or down keys doesn't match curses.KEY_UP or curses.KEY_DOWN respectively. Other...
2
by: mmcnospam | last post by:
Hi I'm pretty new to javascript and cross-browser stuff. I want to restrict text input boxes to only numbers and decimal points and exclude all else....except cursor keys, home keys etc. ...
1
by: VB Gamer | last post by:
In College I made a simple game with picture boxes being moved with the cursor keys. I'm back into programming again with vb.net (that was VB6) and I want to know how to do this again. This is...
2
by: colin | last post by:
Hi, I have a form with some buttons and a graphical user control, I need to use the cursor keys to move the camera position in the control, but it has the unfortunate side effect of cycling...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.