To use Accelerator Tables in an application:
Define the Accelerator Tables required using: AcceleratorTable <name>
Start the entries for each table with: <name> table
Add entries with: ( flags key-code command-id ) AccelEntry
End the table with: ( Window ) HandlesThem This will add code to process the Accelerator Keys in the message chain.
Use: <name> EnableAccelerators to enable the accelerator commands and send them to the window used with HandlesThem.
These accelerator commands are handled in the window's OnWmCommand: method.
Use: <name> DisableAccelerators to disable the accelerator commands for this table. Always disable (destroy) every table before the application closes to prevent memory leaks.
: Dump-Accelerator-Key-Table ( a -- ) \ W32F sys
Dump an Accelerator Table to the console window-
: AcceleratorTable ( <name> -- )
Create a new named Accelerator Table
: Table ( a -- ) \ W32F sys
Start a table of entries in the dictionary
: AccelEntry ( flags key-code command-id -- ) \ W32F sys
Add a entry to the current table
: HandlesThem ( Window -- ) \ W32F
Close a table and assign it to the given window.
: DisableAccelerators ( a -- ) \ W32F
Destroys the Windows Accelerator Table.
: EnableAccelerators ( a -- ) \ W32F
Creates the Windows Accelerator Table.
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ Define some accelerator tables \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ AcceleratorTable FunctionKeys AcceleratorTable CharKeys AcceleratorTable NumKeys \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ Define a small window that will receive the accelerator commands \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ :Object TEST <Super Window :M StartSize: 220 50 ;M :M On_Init: ( -- ) NumKeys EnableAccelerators FunctionKeys EnableAccelerators CharKeys EnableAccelerators ;M :M OnWmCommand: ( hwnd msg wparam lparam -- hwnd msg wparam lparam ) over LOWORD ( Command ID ) cr ." Accelerator command ID: " . ;M :M On_Done: ( -- ) NumKeys DisableAccelerators FunctionKeys DisableAccelerators CharKeys DisableAccelerators ;M ;Object \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ Accelerator table entries \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ NumKeys table \ Flags Key Code Command ID FCONTROL VK_NUMPAD0 0 AccelEntry FCONTROL VK_NUMPAD1 1 AccelEntry FCONTROL VK_NUMPAD2 2 AccelEntry FCONTROL VK_NUMPAD3 3 AccelEntry FCONTROL VK_NUMPAD4 4 AccelEntry FCONTROL VK_NUMPAD5 5 AccelEntry FCONTROL VK_NUMPAD6 6 AccelEntry FCONTROL VK_NUMPAD7 7 AccelEntry FCONTROL VK_NUMPAD8 8 AccelEntry FCONTROL VK_NUMPAD9 9 AccelEntry FCONTROL VK_DECIMAL 16 AccelEntry FCONTROL VK_RETURN 17 AccelEntry FCONTROL VK_ADD 18 AccelEntry FCONTROL VK_SUBTRACT 19 AccelEntry TEST HandlesThem FunctionKeys table \ Flags Key Code Command ID FSHIFT VK_F1 65 AccelEntry FSHIFT VK_F2 66 AccelEntry FSHIFT VK_F3 67 AccelEntry FSHIFT VK_F4 68 AccelEntry TEST HandlesThem CharKeys table \ Flags Key Code Command ID 0 'Z' 129 AccelEntry 0 'X' 130 AccelEntry 0 'C' 131 AccelEntry 0 'V' 132 AccelEntry 0 'B' 133 AccelEntry 0 'N' 134 AccelEntry 0 'M' 135 AccelEntry TEST HandlesThem \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ Instructions \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ cr NumKeys Dump-Accelerator-Key-Table FunctionKeys Dump-Accelerator-Key-Table CharKeys Dump-Accelerator-Key-Table start: test cr .( Make sure the test window has the focus.) cr .( Press some of the accelerator keys to see the IDs in the console window.) cr .( In this example NumPad keys need Ctrl [Num Lock needs to be on].) cr .( Function keys work with Shift, Char keys work without Shift, Ctrl or Alt.) cr .( All combinations of Shift, Ctrl, Alt or nothing are possible.) cr .( CharKeys DisableAccelerators will disable the CharKeys accelerators.) cr .( CharKeys EnableAccelerators will enable them again.) cr .( Closing the Test window will disable all the accelerators)
Document $Id: p-AcceleratorTables.htm,v 1.10 2007/05/26 10:24:11 dbu_de Exp $