Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Identifying keys that have been pressed.

Posted on 2004-07-31
8
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Suggested Courses

722 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