Understanding the Details function

I’m trying to understand how the Details function works with respect to KeyCode. I am using the KeyPressed event in a Web project, and in that event I have tried the following and neither of them do anything when hitting the Tab key on the relevant field:

If details.KeyCode = 9 Then
    MsgBox "Tab key pressed"
  End If
If details.KeyCode = details.KeyTab Then
    MsgBox "Tab key pressed"
  End If

I’m obviously missing something very basic here.

Keycodes are NOT characters.

See http://documentation.xojo.com/index.php/keyboard

Tab keycode is &h30

If you want to compare with chr(9) use Details.Character

Thanks, Michael. I tried each of the following KeyPressed event code snippets, and neither do anything when I press Tab on the relevant field:

If details.KeyCode = &h30 Then
    MsgBox "Tab is pressed"
  End If
If details.Character = chr(9) Then
    MsgBox "Tab is pressed"
  End If

However, if I create a test Desktop project, and do the same, but like this:

  If Keyboard.AsyncKeyDown(&h30) Then
    MsgBox "Tab is pressed"
  End If

It works fine when placed in the field’s KeyDown event handler. What I was trying before was with a Web project.

Desktop & web behave VERY differently in many respects

With a desktop project there is 0 distance between the app and the ui - they’re on the same machine

Not so on the internet
The UI may be running on a machine half way round the world (in the browser) and the App running on a server
So by the time the “keypressed” event gets to the app

  1. the key has already been pressed and more than likely the key released - basically far too late for you to react
  2. there may be a LOT of latency between the user pressing the key & the app being notified about it (thats the nature of the internet)

Using keydown etc on the web is not recommended

After see the result I wanted only on the Desktop version, I started to wonder if that’s what was happening. Thanks, Norman.

I just tested. Tab is not detected, because it is used by the browser for its own UI.

Other keys are.


I tried a few other keys and none worked with the browser (Mac Chrome): ESC, 1, F1.

[quote=245794:@Ralph Alvy]Michel,

I tried a few other keys and none worked with the browser (Mac Chrome): ESC, 1, F1.[/quote]

You may want to use Details.CtrlKey.

But I think you better not use control keys. Depending on the browser, they may not be available.

Try with alphanumeric keys, and your code will work.

Here is an example of code I used to test in the WebPage KeyPressed:

system.DebugLog str(details.CtrlKey) system.DebugLog details.Character

In Chrome it detects Alt, Ctrl, F1, as well as alphanumeric keys.

BUT if you are using for instance Internet Explorer, it does not detect them because IE simply does not honor the Keypressed event for control characters, arrow keys and function keys.

Hmmm…you’re making it more important I don’t bother with coding keypresses here. I’ll stick with things like LostFocus.

Keyboard and mouse events really should be handled client-side.

On the Web, navigation is primarily mouse based.