Assoc. number pad with Command buttons 
Author Message
 Assoc. number pad with Command buttons

Is there any way to associate number pad presses on the
keyboard with Command Buttons in Visual Basic? For
instance, I want to press "9" and activate one button, or
press "5" and activate another.  But in doing this, I'd
still like to use to mouse pointer to click the buttons on
the screen.  Any help would be appreciated.


Sat, 17 Sep 2005 05:12:48 GMT  
 Assoc. number pad with Command buttons
I presume you are looking for behaviour like Calc application. You
can't directly associate number pad with command buttons, but with
some programming tricks you can achieve the same effect.

You can try the following steps :

1. Add a command button array with ten buttons (index 0 to 9) on a
form. Name the array btnNumber. Set their captions from &0 to &9
(ampersand is desired)

2. Set Key Preview property of the form to true.

3. Paste the following code in the form, and let go :
---------------
Option Explicit

Private Sub btnNumber_Click(Index As Integer)
   MsgBox "Button Pressed : " & Index
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
   'ascii 0 -> 48
   'ascii 9 -> 57
   Select Case KeyAscii
      Case 48 To 57
         SendKeys "%" & Chr(KeyAscii), 100
   End Select
End Sub
---------------

Hope this helps...

Vikram
------------------------------------------------
Providing Components For Your Software Solutions
http://www.viklele.com

Quote:

> Is there any way to associate number pad presses on the
> keyboard with Command Buttons in Visual Basic? For
> instance, I want to press "9" and activate one button, or
> press "5" and activate another.  But in doing this, I'd
> still like to use to mouse pointer to click the buttons on
> the screen.  Any help would be appreciated.



Sat, 17 Sep 2005 12:30:22 GMT  
 Assoc. number pad with Command buttons
Set the Form's KeyPreview property to True, this will cause the Form's
KeyPress Event to intercept and evaluate all KeyStrokes first.
Use these constants in the Form_KeyPress Event.

vbKeyNumpad0 96 0 key
vbKeyNumpad1 97 1 key
vbKeyNumpad2 98 2 key
vbKeyNumpad3 99 3 key
vbKeyNumpad4 100 4 key
vbKeyNumpad5 101 5 key
vbKeyNumpad6 102 6 key
vbKeyNumpad7 103 7 key
vbKeyNumpad8 104 8 key
vbKeyNumpad9 105 9 key
vbKeyMultiply 106 MULTIPLICATION SIGN (*) key
vbKeyAdd 107 PLUS SIGN (+) key
vbKeySeparator 108 ENTER (keypad) key
vbKeySubtract 109 MINUS SIGN (-) key
vbKeyDecimal 110 DECIMAL POINT(.) key
vbKeyDivide 111 DIVISION SIGN (/) key

Select Case KeyCode
    Case vbKeyNumpad0: cmd0_Click
    Case vbKeyNumpad1: cmd1_Click
    'Etc.
End Select

hth,
s


Quote:
> Is there any way to associate number pad presses on the
> keyboard with Command Buttons in Visual Basic? For
> instance, I want to press "9" and activate one button, or
> press "5" and activate another.  But in doing this, I'd
> still like to use to mouse pointer to click the buttons on
> the screen.  Any help would be appreciated.



Sun, 18 Sep 2005 21:56:12 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. mimic NT's ASSOC command

2. Login script for running assoc command in Win98

3. Padding out a number

4. number pad problems with datagrid control

5. source for mouse entry number pad

6. mouse driven number pad

7. Padding a number

8. padding numbers going into a file

9. Number pad Code???

10. MMC and Task Pads with VBscript commands

11. Hover Button style command buttons in Access 97?

12. Assign a menu command to a command button in Powerpoint

 

 
Powered by phpBB® Forum Software