473,795 Members | 3,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detect arrow keys at form level

18 New Member
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 11311
sukeshchand
88 New Member
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 New Member
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
sukeshchand
88 New Member
How many forms you are using the project?
Mar 1 '07 #4
Killer42
8,435 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 New Member
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 Recognized Expert Expert
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 New Member
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
8114
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 the code into a user control, put it on the form. Now I don't get keydown events when I press an arrow key - on either the form or the usercontrol ?!!!? I suspect somehow the container fucntionality has decided that they are was of migrating...
6
1934
by: Nathan | last post by:
How can I detect when one of the arrow keys is pressed? Thanks, Nathan
4
5892
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 sensible tab value. The tab key moves the focus down the column one by one, and the up and down arrow keys work well.
11
2810
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
4175
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 PageUp, PageDn, Home, End, and arrow keys for scrolling the Panel control. Resizing the image using the and keys works fine, deriving a resized thumbnail from the image and reassigning it to the Image property of the PictureBox. However I'm...
2
5515
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 control. How do I stop this? Vincent.
1
10157
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 Key. The code below shows what I mean. How can I cure this? (excuse me for the line breaks) */
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...
2
7143
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
0
9672
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
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
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
10163
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
9037
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
6779
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
5436
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
4113
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
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.