473,804 Members | 3,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do u make keyboard arrow keys move a picture box?

Bob
well i pretty much said it in the title.

i was wondering how would you make a picture box or an object repond
to the arrow keys.

for example i have a picture and i want to move right when i press the
right arrow on my keyboard. what is code for that?

if anyones knows the code please answer.

thank you very much.
Jul 17 '05 #1
4 22570

"Bob" <co*******@hotm ail.com> wrote in message
news:2c******** *************** **@posting.goog le.com...
well i pretty much said it in the title.

i was wondering how would you make a picture box or an object repond
to the arrow keys.

for example i have a picture and i want to move right when i press the
right arrow on my keyboard. what is code for that?

if anyones knows the code please answer.

thank you very much.


Try this:

Private sub Form_KeyDown(Ke yCode as integer, Shift as integer)

Select case KeyCode
case vbKeyRight

put what you want it to do here

end select
end sub

I'm showing you a select case style, since it is likely you will have other
keys doing other things and this way it cuts out a lot of if...then stuff.

By the way, the KeyDown event and the keycode constants are available in the
help files.
Jul 17 '05 #2
Bob
thank you but i was just wondering, how does case select work and where is it

used. i haven't programmed in a while and i m trying to re-learn everything

thanky you
Jul 17 '05 #3

"Bob" <co*******@hotm ail.com> wrote in message
news:2c******** *************** **@posting.goog le.com...
thank you but i was just wondering, how does case select work and where is it
used. i haven't programmed in a while and i m trying to re-learn everything
thanky you


Any time you want one action (KeyDown, MouseDown,) or sub to do more than
one thing depending on the value of a variable (MouseX, KeyCode) (or any
other variable), there are two ways to do it.

One is to create a list of if,then,else statements with your code inside
each one. That's asking for slower code and more likelihood for error. The
other is to use a select case arrangement. In that, you simply type select
case (required argument) where the required argument is shown in the
procedure (take a look at Form_KeyDown and notice that it is followed by
KeyCode as one of the required arguments)

then simply type case (what the required argument is) and follow it with the
code you want to execute. When you are all finished with the different
cases, type end select and you're done.

so you could, in the KeyDown example have the following:

if keycode=somethi ng then
do things
end if
if keycode=somethi ng else then
do other things
end if

or you could have
select case keycode
case vbkeyescape
do something
case vbkeya
do something else
end select

See? You should be able to find out more in the Visual Basic help, or with
the purchase of almost any book on Visual Basic.
Jul 17 '05 #4
Bob
Thnx a lot, i understand every now a lot better. i hoep teh program will work now.
Jul 17 '05 #5

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

Similar topics

2
2172
by: Juha-markku Liikala | last post by:
Hi! I've just started to learn PHP, so this may be a dumb quiestion, but I'll ask it anyway... Is it possible to create a photoalbum (or make use of such) with PHP, where I could navigete with my keyboard? When some picture from a gallery would be selected, could I navigate to next or previous picture by using for example buttons "n" and "p" from my keyboard? Is this possible to do with PHP or should I use JavaScript or such instead?
3
19137
by: dreamer | last post by:
I am making a program for a friend with a disability. I need to adjust his audio volume using the keyboard as he cannot use a mouse. Any suggestions as to how I can raise the volume using the up arrow on the keyboard and decrease the volume using the down arrow? I am using VB 5. Many thanks in advance.
3
3602
by: Andrus Moor | last post by:
I want to use the keyboard keys for navigation in menu: 1. Alt+hotkey must activate menu bar 2. Left and right arrow must move between menus, 3. Up and Down arrow move between menu items. 4. Enter key must select menu item. Basically, I want the menu to behave like ordinary OS menu. I have searched the whole web but havent find any such sample.
13
2766
by: Steve Jorgensen | last post by:
Well, it seems that Microsoft, or whatever powers that be have decided it's time for us to have yet another standard keyboard layout change. I think I see that the point of this one was to reduce the space occupied by the keys on the right, so the reach to the mouse is not so bad, but the way they chose to do it? Ah - I see. Since most of what we type will simply be deleted at some point, let's make sure the Delete key is big and easy...
1
3339
by: Richard Coutts | last post by:
I have a Continous Form with 5 or so fields for each record, in a line from left to right. Because the Contuous Form lists several records at once, the form looks pretty much like a Datasheet. So, I'd like to be able to navigate it like one when using the up/down/left/right arrow keys of the keyboard. I have the fields set with tab stop settings so that hitting the tab key moves one field to the right. The problem I'm having is when I...
4
5895
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.
2
5518
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.
2
5767
by: Brice Rebsamen | last post by:
Hi I wrote the following program that reads the keyboard in medium raw mode (keycode mode). Here is the initialization code, the full code is at the end. fd = open("/dev/tty0", O_RDONLY); tcgetattr ( fd, &newkbd ); newkbd.c_lflag &= ~ (ECHO | ICANON | ISIG); newkbd.c_iflag = 0;
2
1732
by: DavidPr | last post by:
I've downloaded an Open Source Maze game and the keys that makes the thingy move through the maze isn't very intuitive and I'd like to change them to the arrow keys. Here's the current setup: /* Set the default keys. (left, right, up, down, pause, solve, hint, save, header, reload) */ var keys = new Array('j','l','i','k','q','s','h','y','c','r'); How can I set the left, right, up and down arrow keys in the var keys array instead of...
0
9706
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
10580
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
10335
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
10323
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
10082
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
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...
1
7621
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4301
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
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.