Skip to content

onkey

The onkey event deserves its own little page as it has some slightly unusual quirks. Basically if you set an onkey function all of your keystroke inputs that occurs will be directed to that event function. OnKey is currently only part of dataform1 form’s and workarounds should be used when using wxform (some examples at the bottom of the page link)

setting onkey

OnKey consists of two events: onkey and onkeylostfocus it is a special control to hold the focus and to direct keystroke input that occurs while that control has focus to the provided function. Additionally if focus is lost, that will also be relayed to the appropriate function

OnKey is a very special event alongside as there are two ways to set up the functions and references, either the standard referencing=@ or using the setkeyfocus()function

setkeyfocus

This function is a part of databaseforms it will do the same as setting functions and refereces manually but in a more friendly manner it is setup as follows:

dataform1var.setkeyfocus (function onkey, type(*) onkeyreference, function onlostfocus, type(*) onlostfocusreference)

All of these parameters are optional and calling without any of them will not cause an error to be returned

Event handling function

The onkey function should be layed out as follows:

function onkey(wxform form, string char, integer keys, type(*) reference)

The parameters of this function have a very limited scope of values that will get passed into them

char will contain either a single character, or else a string describing the key that was pressed. The list of currently supported strings is:

  • “back”
  • “tab”
  • “return”
  • “escape”
  • “delete”
  • “end”
  • “home”
  • “left”
  • “up”
  • “right”
  • “down”
  • “insert”
  • “pageup”
  • “pagedown”
  • “f1″–”f24”

The keys variable will give you which additional keys were held down, it is a collection of bits showing key positions:

Key TypeBit Value
shift down 0x00010000
ctrl down 0x00020000
alt down 0x00040000
meta down 0x00080000

I would advise you have a play around with the actual key and bit values you receive: a simple onkey program has been included at the (bottom of the page) to make this easier for you

Finally the reference contains an optionally defined parameter of user-defined type, as is typical for event handling mechanisms in SIMPOL.

onlostfocus

The onkeylostfocus function is not different to the standard event and thus requires only the following parameters:

dataform1 me[, type(*) reference])

Workarounds

When using wxform there are several work arounds that can be used if you still require keyboard pushes. The first and easiest is using a menu, if in the Label of a menu item you include the following {9} followed by a letter or a keyword (PgDn, PgUp, Left, Right to list a few) pressing that button will now call the onselect function for that menu.

There is an alternative that is a relic of Classic Superbase adding the and symbol (&) and a letter means pressing ALT and that letter will push the button (this is finnicky and requires the focus to be set correctly so shouldn’t be used if you’re looking for reliability)

Downloads