How do I create an accelerator table to handle keyboard input?

Started by tpekar, June 27, 2011, 11:02:02 PM

Previous topic - Next topic

tpekar

Control keys like CTRL-a, ALT-a, and/or F1, F10 etc.  Does anyone have an example of what one looks like?

CommonTater

There is a visual editor for this....

In a project click on File -> New -> Resources
This will create an untitled resource for you.
Right click the untitled item in the right pane.
Select new -> Accelerator Table
This will create a basic table for you
Double click the table item.
Now you have two choices...

Double click on an existing item to change it
Or
Right click and select new to add to the table.

When it's finished just save the file and when asked add it to the project.

This creates the table itself...
To use the table you need to load it at run time using LoadAccelerator() and pass it's handle to the TranslateAccelerator() function in your message dispatcher as I showed you in the other thread.

Inside the .rc file it will look like this...

HOTKEYS ACCELERATORS
{
  80, 1000, VIRTKEY
  VK_SPACE, 1001, VIRTKEY
  83, 1002, VIRTKEY
  VK_PRIOR, 1003, VIRTKEY
  VK_NEXT, 1004, VIRTKEY
  VK_LEFT, 1005, VIRTKEY
  VK_RIGHT, 1006, VIRTKEY
  VK_UP, 1007, VIRTKEY
  VK_DOWN, 1008, VIRTKEY
  49, 1009, VIRTKEY
  50, 1010, VIRTKEY
  51, 1011, VIRTKEY
  52, 1012, VIRTKEY
  VK_RETURN, 1013, VIRTKEY
  84, 1014, VIRTKEY
  88, 1015, VIRTKEY
}


The visual editor makes it very easy to set this up.