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

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 22533

"Bob" <co*******@hotmail.com> wrote in message
news:2c*************************@posting.google.co m...
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(KeyCode 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*******@hotmail.com> wrote in message
news:2c*************************@posting.google.co m...
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=something then
do things
end if
if keycode=something 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
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...
3
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...
3
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....
13
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...
1
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. ...
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...
2
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);...
2
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: /*...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
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.