473,397 Members | 1,949 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,397 software developers and data experts.

Arrow Keys

How can you detect when an arrow key gets pressed? Doesn't seem to trigger
a KeyPress or KeyDown event. Thanks.

Jerry
Nov 21 '05 #1
11 2773
use the KeyDown event.

"Rlrcstr" wrote:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger
a KeyPress or KeyDown event. Thanks.

Jerry

Nov 21 '05 #2
sorry - posted too soon ... use the KeyDown event. check for keys.left and
keys.right. if your KeyDown handler is form-wide, dont forget to set
KeyPreview to true.
"Rlrcstr" wrote:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger
a KeyPress or KeyDown event. Thanks.

Jerry

Nov 21 '05 #3
I'm not getting an event when the arrow is pressed. I do get one when the
space bar is pressed, but not on an arrow press.

Any thoughts?
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
sorry - posted too soon ... use the KeyDown event. check for keys.left
and
keys.right. if your KeyDown handler is form-wide, dont forget to set
KeyPreview to true.
"Rlrcstr" wrote:
> How can you detect when an arrow key gets pressed? Doesn't seem to
> trigger
> a KeyPress or KeyDown event. Thanks.
>
> Jerry
>
>
>

Nov 21 '05 #4
I have no problems with KeyDown getting both arrow key events and space key.
You get space but not arrow. What controls do you have on the form? Almost
certainly the arrow keys are being intercepted by a control on your form.
Search the .net help for "arrow and keydown" for interesting reading.
Nov 21 '05 #5
It's a usercontrol inside a scrollable panel container inside another
usercontrol.

I'm creating the inner usercontrols dynamically and then allowing the user
to scroll through as many as have been created. Kinda like a listbox forthe
usercontrols.

I originally tried actually using an ownerdraw listbox - it has a controls
collection - but it also has issues displaying controls when scrolling, so I
decided to create my own.

I'm very close but I still have to main issues and one of them is that I'm
not getting the KeyDown trigger when an arrow is pressed. I don't
understand why I would get other KeyDown events and not the arrows. It's
strange seems that I get every other key. I even get modified arrows (i.e.
Ctrl + Arrow) but nothing on a plain old arrow.

I will search as you suggested, but in the mean time, if you have any other
thoughts, I'm open...

Jerry

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
I have no problems with KeyDown getting both arrow key events and space
key.
You get space but not arrow. What controls do you have on the form?
Almost
certainly the arrow keys are being intercepted by a control on your form.
Search the .net help for "arrow and keydown" for interesting reading.

Nov 21 '05 #6
Override IsInputKey

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

"Rlrcstr" <rl*****@msn.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
It's a usercontrol inside a scrollable panel container inside another
usercontrol.

I'm creating the inner usercontrols dynamically and then allowing the user
to scroll through as many as have been created. Kinda like a listbox
forthe usercontrols.

I originally tried actually using an ownerdraw listbox - it has a controls
collection - but it also has issues displaying controls when scrolling, so
I decided to create my own.

I'm very close but I still have to main issues and one of them is that I'm
not getting the KeyDown trigger when an arrow is pressed. I don't
understand why I would get other KeyDown events and not the arrows. It's
strange seems that I get every other key. I even get modified arrows
(i.e. Ctrl + Arrow) but nothing on a plain old arrow.

I will search as you suggested, but in the mean time, if you have any
other thoughts, I'm open...

Jerry

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
I have no problems with KeyDown getting both arrow key events and space
key.
You get space but not arrow. What controls do you have on the form?
Almost
certainly the arrow keys are being intercepted by a control on your form.
Search the .net help for "arrow and keydown" for interesting reading.


Nov 21 '05 #7
I started to read something about that. How can you do that with a control
that is instantiated dynamically? Or do I have to create my own subclass?

Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Override IsInputKey

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

"Rlrcstr" <rl*****@msn.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
It's a usercontrol inside a scrollable panel container inside another
usercontrol.

I'm creating the inner usercontrols dynamically and then allowing the
user to scroll through as many as have been created. Kinda like a
listbox forthe usercontrols.

I originally tried actually using an ownerdraw listbox - it has a
controls collection - but it also has issues displaying controls when
scrolling, so I decided to create my own.

I'm very close but I still have to main issues and one of them is that
I'm not getting the KeyDown trigger when an arrow is pressed. I don't
understand why I would get other KeyDown events and not the arrows. It's
strange seems that I get every other key. I even get modified arrows
(i.e. Ctrl + Arrow) but nothing on a plain old arrow.

I will search as you suggested, but in the mean time, if you have any
other thoughts, I'm open...

Jerry

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
I have no problems with KeyDown getting both arrow key events and space
key.
You get space but not arrow. What controls do you have on the form?
Almost
certainly the arrow keys are being intercepted by a control on your
form.
Search the .net help for "arrow and keydown" for interesting reading.



Nov 21 '05 #8
Yes, not hard. You don't even have to create a library to do it.
Public Class UserControl1
Inherits System.Windows.Forms.UserControl

Public Sub New()
Mybase.New()
End Sub

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

End Class
Your form:

Dim Withevents myControl as UserControl1

mycontrol.Parent = '-- Whatever
myControl.Location = '-- Wherever
myControl.Size = '-- Whatever
"Rlrcstr" <rl*****@msn.com> wrote in message
news:Or******************@TK2MSFTNGP14.phx.gbl...
I started to read something about that. How can you do that with a control
that is instantiated dynamically? Or do I have to create my own subclass?

Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Override IsInputKey

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

"Rlrcstr" <rl*****@msn.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
It's a usercontrol inside a scrollable panel container inside another
usercontrol.

I'm creating the inner usercontrols dynamically and then allowing the
user to scroll through as many as have been created. Kinda like a
listbox forthe usercontrols.

I originally tried actually using an ownerdraw listbox - it has a
controls collection - but it also has issues displaying controls when
scrolling, so I decided to create my own.

I'm very close but I still have to main issues and one of them is that
I'm not getting the KeyDown trigger when an arrow is pressed. I don't
understand why I would get other KeyDown events and not the arrows.
It's strange seems that I get every other key. I even get modified
arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.

I will search as you suggested, but in the mean time, if you have any
other thoughts, I'm open...

Jerry

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
I have no problems with KeyDown getting both arrow key events and space
key.
You get space but not arrow. What controls do you have on the form?
Almost
certainly the arrow keys are being intercepted by a control on your
form.
Search the .net help for "arrow and keydown" for interesting reading.



Nov 21 '05 #9
Makes perfect sense. Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Yes, not hard. You don't even have to create a library to do it.
Public Class UserControl1
Inherits System.Windows.Forms.UserControl

Public Sub New()
Mybase.New()
End Sub

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

End Class
Your form:

Dim Withevents myControl as UserControl1

mycontrol.Parent = '-- Whatever
myControl.Location = '-- Wherever
myControl.Size = '-- Whatever
"Rlrcstr" <rl*****@msn.com> wrote in message
news:Or******************@TK2MSFTNGP14.phx.gbl...
I started to read something about that. How can you do that with a
control that is instantiated dynamically? Or do I have to create my own
subclass?

Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Override IsInputKey

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

"Rlrcstr" <rl*****@msn.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
It's a usercontrol inside a scrollable panel container inside another
usercontrol.

I'm creating the inner usercontrols dynamically and then allowing the
user to scroll through as many as have been created. Kinda like a
listbox forthe usercontrols.

I originally tried actually using an ownerdraw listbox - it has a
controls collection - but it also has issues displaying controls when
scrolling, so I decided to create my own.

I'm very close but I still have to main issues and one of them is that
I'm not getting the KeyDown trigger when an arrow is pressed. I don't
understand why I would get other KeyDown events and not the arrows.
It's strange seems that I get every other key. I even get modified
arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.

I will search as you suggested, but in the mean time, if you have any
other thoughts, I'm open...

Jerry

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
>I have no problems with KeyDown getting both arrow key events and space
>key.
> You get space but not arrow. What controls do you have on the form?
> Almost
> certainly the arrow keys are being intercepted by a control on your
> form.
> Search the .net help for "arrow and keydown" for interesting reading.



Nov 21 '05 #10
I spoke too soon. It makes sense, but it doesn't seem to work.

I created the new class and replaced my New statement with the new class,
but the IsInputKey function in the subclass never gets called - I get the
same behavior. No arrows.

These controls are in a panel control. Do I have to subclass that guy? Is
it absorbing the keystrokes? Or do I have to subclass each of the child
controls (checkboxes and labels) on the new usercontrol and do the same
thing with them? This just seems so much more complicated that it should
be, just to capture an arrow key press.

Thanks.

Jerry

"Rlrcstr" <rl*****@msn.com> wrote in message
news:uS**************@TK2MSFTNGP14.phx.gbl...
Makes perfect sense. Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Yes, not hard. You don't even have to create a library to do it.
Public Class UserControl1
Inherits System.Windows.Forms.UserControl

Public Sub New()
Mybase.New()
End Sub

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

End Class
Your form:

Dim Withevents myControl as UserControl1

mycontrol.Parent = '-- Whatever
myControl.Location = '-- Wherever
myControl.Size = '-- Whatever
"Rlrcstr" <rl*****@msn.com> wrote in message
news:Or******************@TK2MSFTNGP14.phx.gbl...
I started to read something about that. How can you do that with a
control that is instantiated dynamically? Or do I have to create my own
subclass?

Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Override IsInputKey

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

"Rlrcstr" <rl*****@msn.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
> It's a usercontrol inside a scrollable panel container inside another
> usercontrol.
>
> I'm creating the inner usercontrols dynamically and then allowing the
> user to scroll through as many as have been created. Kinda like a
> listbox forthe usercontrols.
>
> I originally tried actually using an ownerdraw listbox - it has a
> controls collection - but it also has issues displaying controls when
> scrolling, so I decided to create my own.
>
> I'm very close but I still have to main issues and one of them is that
> I'm not getting the KeyDown trigger when an arrow is pressed. I don't
> understand why I would get other KeyDown events and not the arrows.
> It's strange seems that I get every other key. I even get modified
> arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
>
> I will search as you suggested, but in the mean time, if you have any
> other thoughts, I'm open...
>
> Jerry
>
> "AMercer" <AM*****@discussions.microsoft.com> wrote in message
> news:A3**********************************@microsof t.com...
>>I have no problems with KeyDown getting both arrow key events and
>>space key.
>> You get space but not arrow. What controls do you have on the form?
>> Almost
>> certainly the arrow keys are being intercepted by a control on your
>> form.
>> Search the .net help for "arrow and keydown" for interesting reading.
>
>



Nov 21 '05 #11
Got it...

You have to override IsInputKey in the child controls and return true for
keys that you want the parent to see and then override processKeyPreview in
the parent and look for those keystrokes.

Thanks for your help. On to the next hurdle...

Jerry

Have to override the processKeyPreview event in the usercontrol
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Yes, not hard. You don't even have to create a library to do it.
Public Class UserControl1
Inherits System.Windows.Forms.UserControl

Public Sub New()
Mybase.New()
End Sub

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

End Class
Your form:

Dim Withevents myControl as UserControl1

mycontrol.Parent = '-- Whatever
myControl.Location = '-- Wherever
myControl.Size = '-- Whatever
"Rlrcstr" <rl*****@msn.com> wrote in message
news:Or******************@TK2MSFTNGP14.phx.gbl...
I started to read something about that. How can you do that with a
control that is instantiated dynamically? Or do I have to create my own
subclass?

Thanks.

Jerry
"Some Guy" <my*****@there.com> wrote in message
news:11*************@corp.supernews.com...
Override IsInputKey

Protected Overrides Function IsInputKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
IsInputKey = True
End Function

"Rlrcstr" <rl*****@msn.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
It's a usercontrol inside a scrollable panel container inside another
usercontrol.

I'm creating the inner usercontrols dynamically and then allowing the
user to scroll through as many as have been created. Kinda like a
listbox forthe usercontrols.

I originally tried actually using an ownerdraw listbox - it has a
controls collection - but it also has issues displaying controls when
scrolling, so I decided to create my own.

I'm very close but I still have to main issues and one of them is that
I'm not getting the KeyDown trigger when an arrow is pressed. I don't
understand why I would get other KeyDown events and not the arrows.
It's strange seems that I get every other key. I even get modified
arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.

I will search as you suggested, but in the mean time, if you have any
other thoughts, I'm open...

Jerry

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
>I have no problems with KeyDown getting both arrow key events and space
>key.
> You get space but not arrow. What controls do you have on the form?
> Almost
> certainly the arrow keys are being intercepted by a control on your
> form.
> Search the .net help for "arrow and keydown" for interesting reading.



Nov 21 '05 #12

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

Similar topics

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...
2
by: Darren Oakey | last post by:
ok - the problem - I made a simple breakout game out of a form, just painting the background - and using keydown for left and right arrow keys to control the bat - worked fine. I then moved all...
4
by: Neil Wallace | last post by:
Hi there, I have an application in which a grid of 100 or more buttons are put on a form in columns of 10. All the buttons are within a panel. They are added in runtime, and so they adopt a...
2
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user...
1
by: Martijn Mulder | last post by:
/* I have problems detecting the Arrow Keys on a User Control. A control derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys but does react on the combination <Altor <Ctrl+ Arrow...
0
by: Martijn Mulder | last post by:
/* 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...
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,...
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...
4
by: beary | last post by:
Hi Being tested using FF 3 on WAMP server. I have spent a number of hours trying to figure this out myself. I have a html form using table cells and had a request to enable the arrow keys on a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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.