Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Identifying keys that have been pressed.

Posted on 2004-07-31
8
Medium Priority
?
182 Views
Last Modified: 2011-10-03
I am creating a music player. And i want to have keys associated with commands. I have 3 problems:
How to read what keys have been pressed.
How to associate key combinations with code
How to read the data when the program is not in focus (like running on the system tray or minimised)

I don't think that the first two problems are that difficult but the last one might be a little more tricky.

Thanks in adavance

Alex
0
Comment
Question by:Completenutter2
  • 5
  • 2
8 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 11684175
The rules of this site do not allow more than one question at a time. As the first two questions are related then hee you go:


'Use the keydown or keyUp events to read the keys that were pressed and to associate them with commands:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
    Case vbKeyA 'a was pressed
        'associate with a command - do your stuff
    Case vbKeyF1 'the F1 key was pressed
        'associate with another command - do the other stuff
    case .....
   
End Select
End Sub

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11684190
ps. As per your third question. I suggest your ask it in a separate question, and explaine in more details what data you want to read, from where to to where.

S
0
 

Author Comment

by:Completenutter2
ID: 11684317
OK that sounds like it would work for standard keys but how about non-standard keys like multi media  keys on a keyboard. I've seen it in winamp.

Thanks for the standard key bit :)

Alex
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 19

Expert Comment

by:Shauli
ID: 11684511
Well, you need to know the combination fo these keys, however, here is an example:

If KeyCode = vbKeyB And (Shift And vbCtrlMask > 0) Then 'either control or shift or alt key were pressed along with the B key.
    'do your stuff
End If

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11684518
ps. To determine if it is a shift the control or the alt key then if (Shift And vbCtrlMask)=1 (shift) 2 (control) 4 (alt).

S
0
 

Author Comment

by:Completenutter2
ID: 11684527
Would there not be a way to capture the keys pressed? I know that the stop button uses Ctrl + S but the Play/Pause button is read in winamp as Play/Pause and not a key combo.
0
 
LVL 19

Accepted Solution

by:
Shauli earned 600 total points
ID: 11684575
0
 
LVL 5

Assisted Solution

by:Barsham
Barsham earned 150 total points
ID: 11692706
You can use DirectInput Api to Read Key From Where Pressed
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question