Solved

VK_SPACE

Posted on 2007-04-09
3
1,928 Views
Last Modified: 2013-12-03
Hi,

I want to make some hotkeys for my application. I want to bind the space bar. - but space bar doesn't have an ascii code, it has a virtual key code. Is that virtual key code value consistent for all keyboards? I'm trying something like:

    // VK_SPACE on my machine is defined on 0x20.

    LRESULT ViewBase::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message) {
            case 0x20:
                 AfxMessageBox("User pressed space bar.");
                 break;
        }
}

Thanks




0
Comment
Question by:DJ_AM_Juicebox
  • 3
3 Comments
 
LVL 9

Expert Comment

by:Priyesh
ID: 18880244
Yes it is. AFAIK.
0
 
LVL 9

Accepted Solution

by:
Priyesh earned 500 total points
ID: 18880246
I meant VK_SPACE is consistent.
Although you might want to change your WindowProc to

    LRESULT ViewBase::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message) {
            case WM_KEYDOWN:
                 if(wParam == VK_SPACE)
                    AfxMessageBox("User pressed space bar.");
                 break;
        }
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 18880252
I think you are wanting to make accelerators. Try editing your accelerator in your resources. Add the keys you want commands for there. Then you can add ON_COMMAND handlers for those in your view.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 event 3 95
Need an intro to -- .Net SQL Authorization Manager 7 87
Trouble with References... 5 54
Message not shown 5 49
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

776 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