Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 49acc3eec5
Fetching contributors…

Cannot retrieve contributors at this time

file 63 lines (51 sloc) 2.195 kb

Accelerator (RT_ACCELERATOR)

An accelerator is a keystroke defined by the application to give the user a quick way to perform a task.

When ResourceInfo encouters a resource of type 9 (RT_ACCELERATOR), it creates an object of type AcceleratorResource which contains a collection of instances of Accelerator.

Reading Accelerator Resources

The following example loads all accelerator resources from a file.

string filename = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
using (ResourceInfo ri = new ResourceInfo())
{
    ri.Load(filename);
    foreach(AcceleratorResource rc in ri[Kernel32.ResourceTypes.RT_ACCELERATOR])
    {
        Console.WriteLine("AcceleratorResource: {0}, {1}", rc.Name, rc.TypeName);
        Console.WriteLine(rc);
    }
}

Explorer.exe contains the following accelerator table.

Resource: 251 of type RT_ACCELERATOR, 88 byte(s) [en-US]
251 ACCELERATORS
BEGIN
 VK_F4, 305, ALT
 VK_TAB, 41008, VIRTKEY , NOINVERT
 VK_TAB, 41008, VIRTKEY , NOINVERT , SHIFT
 VK_TAB, 41008, VIRTKEY , NOINVERT , CONTROL
 VK_TAB, 41008, VIRTKEY , NOINVERT , SHIFT , CONTROL
 VK_F5, 41061, VIRTKEY , NOINVERT
 VK_F6, 41008, VIRTKEY , NOINVERT
 VK_RETURN, 413, VIRTKEY , NOINVERT , ALT
 Z, 416, VIRTKEY , NOINVERT , CONTROL
 VK_F3, 41093, VIRTKEY , NOINVERT
 M, 419, VIRTKEY , NOINVERT , ALT
END

Reading Specific Accelerator Resources

The following example loads a single accelerator resource directly, without enumerating all resources.

string filename = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
AcceleratorResource rc = new AcceleratorResource();
rc.Name = new ResourceId(251);
rc.LoadFrom(filename);
Console.WriteLine("AcceleratorResource: {0}, {1}", rc.Name, rc.TypeName);
Console.WriteLine(rc);

Writing an Accelerator Table

In order to add an accelerator into an executable (.exe or .dll) create a new instance of AcceleratorResource or load an existing one and add instances of Accelerator to its Accelerators collection.

Something went wrong with that request. Please try again.