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

How to get the Key press function working

Hello everyone..

Let me tell where i am in my programming..

I have 3 command buttons in my form. say a, b,c

When I press the Key A in keyboard, I need the color of my command buton A to change. Similarly for If I press the keys B and C, I need the corresponding commandbuttons to change in color.

I am using the following code but I am not able to get the result.

Private Sub Command1_KeyPress(KeyAscii As Integer)
Call Form_KeyPress(KeyAscii)
End Sub


Private Sub Command2_KeyPress(KeyAscii As Integer)
Call Form_KeyPress(KeyAscii)
End Sub


Private Sub Command3_KeyPress(KeyAscii As Integer)
Call Form_KeyPress(KeyAscii)
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 65
Command1.BackColor = QBColor(Rnd * 15)

Case 66
Command2.BackColor = QBColor(Rnd * 15)

Case 67
Command3.BackColor = QBColor(Rnd * 15)

End Select
end sub

I think I am missing something somewhere.. Can anyone please help for this thread..
Sep 17 '06 #1
1 7459
Note there are always many ways to do something in VB code. I use the following to show active command buttons and labels.

1-Make sure that your button style is set to graphical for all buttons.
2-Make one form mousemove sub to restore all buttons to original colors.
3-Use the command button mousemove to change the color

Public sub cmdA_MouseMove( )
call clearback
cmdA.backcolor=vbgreen
end sub

Public sub cmdB_MouseMove( )
call clearback
cmdB.backcolor=vbgreen
end sub

Public sub cmdC_MouseMove( )
call clearback
cmdC.backcolor=vbgreen
end sub

Public sub form1_mousemove( )
call clearcolor
end sub

Public sub clearcolor( )
normal=&H8000000F&
if cmdA.backcolor=vbgreen then cmdA.backcolor=normal
if cmdB.backcolor=vbgreen then cmdB.backcolor=normal
if cmdC.backcolor=vbgreen then cmdC.backcolor=normal

end sub


Hello everyone..

Let me tell where i am in my programming..

I have 3 command buttons in my form. say a, b,c

When I press the Key A in keyboard, I need the color of my command buton A to change. Similarly for If I press the keys B and C, I need the corresponding commandbuttons to change in color.

I am using the following code but I am not able to get the result.

Private Sub Command1_KeyPress(KeyAscii As Integer)
Call Form_KeyPress(KeyAscii)
End Sub


Private Sub Command2_KeyPress(KeyAscii As Integer)
Call Form_KeyPress(KeyAscii)
End Sub


Private Sub Command3_KeyPress(KeyAscii As Integer)
Call Form_KeyPress(KeyAscii)
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 65
Command1.BackColor = QBColor(Rnd * 15)

Case 66
Command2.BackColor = QBColor(Rnd * 15)

Case 67
Command3.BackColor = QBColor(Rnd * 15)

End Select
end sub

I think I am missing something somewhere.. Can anyone please help for this thread..
Sep 17 '06 #2

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

Similar topics

1
by: Brian Basquille | last post by:
Can i carry out a command during execution with the press of a key? Am working on a Countdown Timer and everytime i press p on the keyboard, i want to add a minute to the timer and every time i...
3
by: John Howard | last post by:
I'm trying to write a simple press any key routine, but am having some problems. Here is the routine: void PressAnyKey () { cout << "Press Any Key"; do{}while (!kbhit()); getch(); cout <<...
7
by: JCO | last post by:
How's come when I press the enter key, I can't get it to execute the correct password. It seems that I'm forced to press the button. I want to be able to do both. How is this done?
3
by: raj | last post by:
hi, i have one textbox and one save button, i have added attribute at page load event btnSave.Attributes.Add("onclick","return ValidateForm();"); in validationform() ,I have written like this...
0
by: neeraj | last post by:
Hi Everybody I have one problem in my asp.net web application. The problem is that I check the date validation in code behind; if user not gives the valid data and press save button then I fire...
6
by: Kürşat | last post by:
Hi, I want to get all key press messages and for some keys I want to generate extra key press messages to simulate fast typing. For example if someone press 'H' my app should catch and change...
4
by: almurph | last post by:
Hi everyone, I'm a newbie to javascript. I have written some code to detect when a user presses the down-arrow, up-arrow and enter button. Essentially the user can arrow down or up through a...
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
2
by: deepikashalini | last post by:
In javascript i call a function at the time of to press an enter key. number of times i press a key the process will be activated. hoow to i ignore this problem <input type="password"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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...

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.