456 ObjectPAL: keyEventVERSIONS: All ? - written for Paradox 5
SUBJECT: Keychar() and Keyphysical()
BY: William F. Hannan
QUESTION:
Could someone please take a few minutes and explain the keychar and keyphysical methods to me? Also, give me a brief example?
This should get you started.
Using keyPhysical() you can trap/test_for any keyboard entry, regardless as to whether it is printable or not. With keyChar() you can only trap/test_for printable characters. KeyPhysical() is called first and then if the character is printable keyChar is called.
Within both keyPhysical and keyChar you use the methods vChar() and vCharCode() with the eventInfo packed to retrieve the string character or integer code of the character entered on the keyboard.
Ex.
someString = eventInfo.vchar()
someInt = eventInfo.vCharCode()
The 2 methods are interchangeable, but you must be consistent. If you use vChar() you test against strings, if you use vCharCode() you test against integers.
If the letter "A" was entered with the key board
if eventInfo.vChar() = "A" then..
and
if eventInfo.vChar() = 65 then..
would both return true.
The normal way to test for non-printable characters is to compare the eventInfo character to the Windows virtual key codes. To test for tab either of the following would work in the keyPhysical method
if eventInfo.vChar() = "VK_TAB" then...
or
if eventInfo.vCharCode() = VK_TAB
The VK_ constants can be found in the on-line help under- keyphysical, or by right clicking the mouse in any edit window and choosing constants, then choose key codes.
In the last example my preference would be the 2nd,
if eventInfo.vCharCode() = VK_TAB
when using the constants as integers they are not case sensitive that is, vk_TAB = VK_TAB. If you use the first example with the constant, IT IS CASE SENSITIVE "vk_tab" will not trap a TAB. Also if you have a typo like "VK_TSB" the syntax checker will not catch it when you compile, it is just another string, but without the quotes in the 2nd example VK_TSB would cause an unknown constant error.
I always like the syntax checker to find as many of my typos as possible.
When using either of the methods the value returned is NOT CASE SENSITIVE both "a" and "A" will return the same value "A". To test for case you need to use isShiftKeyDown(). Use isControlKeyDown() and isAltKeyDown() to test for the corresponding shift states.
If eventInfo.vChar() = "A" and eventInfo.isShiftKeyDown() then
; it's an upper case "A"
endIf