6 Replies - 3628 Views - Last Post: 22 June 2008 - 05:50 AM Rate Topic: -----

#1 MrC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-June 08

match keyboard keys with form buttons

Post icon  Posted 21 June 2008 - 09:43 AM

I am writing a calculator program and I want to be able to use my number keypad to input as well as my mouse to click buttons.
How do I match keyboard keys with specific buttons?

many thanks

C
Is This A Good Question/Topic? 0
  • +

Replies To: match keyboard keys with form buttons

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: match keyboard keys with form buttons

Posted 21 June 2008 - 03:17 PM

Just use the keydown (or keyup) event. Check if the key is being pressed (using its keycode), and have it execute the code that the button would.

This post has been edited by Zhalix: 21 June 2008 - 03:17 PM

Was This Post Helpful? 1
  • +
  • -

#3 MrC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-June 08

Re: match keyboard keys with form buttons

Posted 22 June 2008 - 04:48 AM

View PostZhalix, on 21 Jun, 2008 - 03:17 PM, said:

Just use the keydown (or keyup) event. Check if the key is being pressed (using its keycode), and have it execute the code that the button would.



zhalix, thanks for your reply.

I have been playing around with the key events already along these kind of lines

Private Sub frmCalculator_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.NumPad0 Then
btn0.PerformClick()
End If
If e.KeyCode = Keys.NumPad1 Then
btn1.PerformClick()
End If
End Sub

The perform click is something I found in the help but nithing is happening for me. Am I right to use the keydown event of the form?
many thanks
C
Was This Post Helpful? 0
  • +
  • -

#4 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: match keyboard keys with form buttons

Posted 22 June 2008 - 05:15 AM

To make sure that it is indeed processing then use message box in them. That way your sure that the code is executing.

for the PerformClick method why not just call the proper method name of your buttons. ie: button1_onclick
Was This Post Helpful? 1
  • +
  • -

#5 MrC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-June 08

Re: match keyboard keys with form buttons

Posted 22 June 2008 - 05:24 AM

View Postmensahero, on 22 Jun, 2008 - 05:15 AM, said:

To make sure that it is indeed processing then use message box in them. That way your sure that the code is executing.

for the PerformClick method why not just call the proper method name of your buttons. ie: button1_onclick



sorry to sound really thick but what do you mean by use message box in them? also I have a lot of my buttons grouped together that serve the same function i.e. numbers 1 through 9. one method e.g. numbers_click handles btn1.click, btn2.click etc. so I can't call an individual method for each button
Was This Post Helpful? 0
  • +
  • -

#6 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: match keyboard keys with form buttons

Posted 22 June 2008 - 05:34 AM

The way I see it thats not vb6 coding but still it has a messagebox function.

messagebox is that best way to test your code if it is indeed executing.

example:


if a = b then
  msgbox "Success"
else
  msgbox "failed"
end if



That is written in vb6 but the logic applies to all.

and About your methods its all based in your coding design. I think your button controls has a onclick event and you put your code there, right?
Was This Post Helpful? 0
  • +
  • -

#7 MrC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-June 08

Re: match keyboard keys with form buttons

Posted 22 June 2008 - 05:50 AM

View Postmensahero, on 22 Jun, 2008 - 05:34 AM, said:

The way I see it thats not vb6 coding but still it has a messagebox function.

messagebox is that best way to test your code if it is indeed executing.

example:


if a = b then
  msgbox "Success"
else
  msgbox "failed"
end if



That is written in vb6 but the logic applies to all.

and About your methods its all based in your coding design. I think your button controls has a onclick event and you put your code there, right?



just realised I should have posted in vb.net forum. Had a look at msgbox though. Definitly good for testing. thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1