Solved

Identifying keys that have been pressed.

Posted on 2004-07-31
8
176 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 55
VBA error replacing data 6 37
passing parameter in sql procedure 9 56
How to compare ms sql hashbytes results within vb6 5 55
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

910 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

15 Experts available now in Live!

Get 1:1 Help Now