Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide to Clip-4-Win version 3.0 - <b>akey</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
AKEY
Define an accelerator key
------------------------------------------------------------------------------

Syntax
#include "accel.ch"
AKEY  <cnKey>, <nId>
      [ , VIRTKEY ]  [ , CONTROL ]  [ , SHIFT ]  [ , ALT ]

Arguments
<cnKey> is either a character string or a numeric value
specifying the key.  The value specified can be qualified by
the optional VIRTKEY, CONTROL, SHIFT, and ALT keywords.

If <cnKey> is a character string, it can be a single character
(specifying the character indicated), or a caret ("^")
followed by a single character (specifying a Control-key
combination).

If <cnKey> is a numeric value, it is usually one of the
virtual keys, defined as VK_* in ACCEL.CH.

<nId> is a numeric id to generate if the accelerator key
combination is used by the user.

Description
This command defines an individual accelerator (short-cut)
key.  Before the AKEY command, you must use the ACCELERATORS
command.

The definitions are built up in the AccelKeyList variable,
which is usually declared as a LOCAL.

After the END ACCELERATORS command, the accelerators can be
activated by the USE ACCELERATORS command.

You can also load an accelerator table from a resource file,
using the LoadAccelerators() function.

Each accelerator key can specify zero or more of the CONTROL,
SHIFT and/or ALT keys.  The user must use the exact combination
specified for it to be recognised as an accelerator.

When an accelerator is used, an EVENT_ACCELKEY is generated,
and the numeric id can be recovered by the _LastwParam()
function.  It is not necessary that an accelerator be a short-
cut for a menu item, although that is usually the case.  The
example below shows accelerators that are independent of the
menu, and also accelerators that provide short-cuts for menu
items.

Example
#include "accel.ch"

#define   ID_HELP   1000      // must use id's over 500
#define   ID_FIND   1001

#define   ID_COPY   1011
#define   ID_PASTE  1012

local     AccelKeyList

ACCELERATORS

AKEY VK_F1,    ID_HELP,  VIRTKEY             // F1
AKEY VK_F4,    ID_FIND,  VIRTKEY, SHIFT      // Shift-F4
// you can do Control-Key like this:
AKEY "^V",          ID_PASTE                 // Control-V
// or like this:
AKEY "C",      ID_COPY,  CONTROL             // Control-C

END ACCELERATORS

USE ACCELERATORS

// . . .

// here is an example of handling some accelerators:
do while .t.
     do while (nEvent := ChkEvent()) == EVENT_NONE
     enddo
     do case
     case nEvent == EVENT_ACCELKEY
          DoAccelerators()
     // . . .
     endcase
enddo


procedure DoAccelerators()
local     nId := _LastwParam()
do case
case nId == ID_HELP
     DoHelp()
case nId == ID_FIND
     DoFind()
case nId == ID_COPY
     // same as menu item Edit...Copy  (with id "copy")
     eval( GetMenuBlock( hMenu, "copy" ) )
case nId == ID_PASTE
     // same as menu item Edit...Paste  (with id "paste")
     eval( GetMenuBlock( hMenu, "paste" ) )
endcase
return


See Also: ACCELERATORS END ACCELERATORS USE ACCELERATORS

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson