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!
9 11311
Set the forms Keypreview property true
and try this code - Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
Select Case KeyCode
-
Case vbKeyUp
-
Form1.Print "Up Arrow Pressed"
-
Case vbKeyDown
-
Form1.Print "Down Arrow Pressed"
-
Case vbKeyLeft
-
Form1.Print "Left Arrow Pressed"
-
Case vbKeyRight
-
Form1.Print "Right Arrow Pressed"
-
End Select
-
End Sub
Set the forms Keypreview property true
and try this code - Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
-
Select Case KeyCode
-
Case vbKeyUp
-
Form1.Print "Up Arrow Pressed"
-
Case vbKeyDown
-
Form1.Print "Down Arrow Pressed"
-
Case vbKeyLeft
-
Form1.Print "Left Arrow Pressed"
-
Case vbKeyRight
-
Form1.Print "Right Arrow Pressed"
-
End Select
-
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!
How many forms you are using the project?
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.
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!
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.
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
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
by: Nathan |
last post by:
How can I detect when one of the arrow keys is pressed?
Thanks,
Nathan
|
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.
|
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
|
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...
| |
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.
|
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)
*/
|
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...
|
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
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
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...
|
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: 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...
| |