There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Keypress mimic mouse click


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
tim8w's Avatar
Member with 35 posts.
 
Join Date: Nov 2004
Experience: New VB6 Programmer
07-Dec-2004, 12:12 PM #1
Cool Keypress mimic mouse click
Anyone know how to have a keypress mimic the mouse clicking on a button. i.e. I have a button with the number "1" on it. When I press the number 1 key, I would like the button "1" to go up and down like it was pressed with the mouse. VB6


Thanks,
Tim
Mosaic1's Avatar
Distinguished Member with 7,498 posts.
 
Join Date: Aug 2001
09-Dec-2004, 01:08 PM #2
Here's the thing. Do you have any other controls on the form which accept keypresses? Like a combo or text box. And if so, if they have the focus when you press they will receive the #1 too. But you know that.

To remove that possibility, reset the key to 0 if pressed. This way nothing happens. This will unfortunately remove your ability to type the number 1 into the text box. You could get around that if need be.

Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 49 Then KeyAscii = 0
End Sub
In the form's properties, set Key Preview to True.
Add this code to your form. It says if the 1 key is pressed, then the Command button's click event is called. If you want to use the Keypad then Numlock has to be set first or it won't work.
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 49 Then Command1_Click
End Sub
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:56 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.