Solved

Identifying keys that have been pressed.

Posted on 2004-07-31
8
173 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 200 total points
ID: 11684575
0
 
LVL 5

Assisted Solution

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

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now