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

Detect arrow keys at form level

18
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!
Feb 11 '07 #1
9 11201
Set the forms Keypreview property true
and try this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2. Select Case KeyCode
  3.     Case vbKeyUp
  4.         Form1.Print "Up Arrow Pressed"
  5.     Case vbKeyDown
  6.         Form1.Print "Down Arrow Pressed"
  7.     Case vbKeyLeft
  8.         Form1.Print "Left Arrow Pressed"
  9.     Case vbKeyRight
  10.         Form1.Print "Right Arrow Pressed"
  11. End Select
  12. End Sub
Feb 11 '07 #2
Anish G
18
Set the forms Keypreview property true
and try this code

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2. Select Case KeyCode
  3.     Case vbKeyUp
  4.         Form1.Print "Up Arrow Pressed"
  5.     Case vbKeyDown
  6.         Form1.Print "Down Arrow Pressed"
  7.     Case vbKeyLeft
  8.         Form1.Print "Left Arrow Pressed"
  9.     Case vbKeyRight
  10.         Form1.Print "Right Arrow Pressed"
  11. End Select
  12. End Sub
================================================
Hi,

Thanks for the reply.

However, I am still having some issues with this Key Down event.

My project has a Main form, in that there is are 3 frames, a tab control, few textboxes, buttons, a picture box and a third party image control (Pegasus Image Control).

Now, the issue is key down event is fired only if I click (using mouse) on the main form or on any of the textboxes present inside the frame control. I mean after that no Key Down events gets fired. I need to click again on the main form or on any of the text box (using mouse) to fire the Key Down Event again.

I spent whole day in finding a fix for this issue, but no success. Please guide me. Do I need to change any other control present inside the form?

Thanks!
Mar 1 '07 #3
How many forms you are using the project?
Mar 1 '07 #4
Killer42
8,435 Expert 8TB
The various events such as KeyDown, KeyUp etc. will normally only apply to the window that currently has the focus. I believe there has been some discussion here recently of a way to get around this problem in VB.Net - unfortunately I don't recall what conclusions were reached.
Mar 1 '07 #5
Anish G
18
How many forms you are using the project?
Hi,

There are 26 forms in the whole project. I want to enable keyboard events only for one form.

Let me know, if you need any further information.

Thanks!
Mar 1 '07 #6
Killer42
8,435 Expert 8TB
What version of VB are you using?

I think VB.Net may be able to do what you want, but VB6 may not - unless you can intercept Windows messages.


I'd suggest you try some searches, on TheScripts and maybe the wider web, for likely combinations of terms such as VB, key and capture.
Mar 1 '07 #7
Anish G
18
What version of VB are you using?

I think VB.Net may be able to do what you want, but VB6 may not - unless you can intercept Windows messages.


I'd suggest you try some searches, on TheScripts and maybe the wider web, for likely combinations of terms such as VB, key and capture.
Hi,

I am using vb6.0
Mar 1 '07 #8
Killer42
8,435 Expert 8TB
I am using vb6.0
Ok.

And do you need your main form to capture keyboard input at all times, or only while your application has the focus? I imagine that will probably make a difference.
Mar 1 '07 #9
Anish G
18
Ok.

And do you need your main form to capture keyboard input at all times, or only while your application has the focus? I imagine that will probably make a difference.

Thanks!

I need the form to capture keyboard events all the time.
Mar 3 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
6
by: Nathan | last post by:
How can I detect when one of the arrow keys is pressed? Thanks, Nathan
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...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
by: Phil Galey | last post by:
I have a Panel control docked on all sides on a form and the panel control contains a PictureBox. I'm using the KeyDown event of the form to respond to the and keys for resizing the image and the...
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...
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: 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...
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: 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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.