KeyPressed event issues

A quicke glimpse into Feedback (30 cases!) tells me that KeyPresses seems to be a mess;
While it doesn’t work on the WebDialog class at all, it at least works on text input objects in Firefox, not in Chrome though.

Any chance that will get some love any time soon?

Best,
Alex

[quote=160225:@Alex von Siebenthal]A quicke glimpse into Feedback (30 cases!) tells me that KeyPresses seems to be a mess;
While it doesn’t work on the WebDialog class at all, it at least works on text input objects in Firefox, not in Chrome though.[/quote]

Apparently, KeyPressed works fine in TextFields, TextAreas and WebPages displayed in Chrome.

At least not here on a Mac.
I’ll try to make a demo project.

[quote=160238:@Alex von Siebenthal]At least not here on a Mac.
I’ll try to make a demo project.[/quote]

I just tested on a Mac, Yosemite 2014R3.2. Here is the project :
https://dl.dropboxusercontent.com/u/17407375/keypressed.xojo_binary_project

When you punch a key at the window level or whenever a text control has the focus, it displays a Msgbox.

First of all, key events only work with native controls. Any control that we created from scratch currently has no way to receive the focus, and so key events can’t be captured on them.

That said, it’s something on the list to tackle when we convert Web to the new framework.

Greg,
Aren’t both the TextArea and the TextField native?

[quote=163774:@Alex von Siebenthal]Greg,
Aren’t both the TextArea and the TextField native?[/quote]
They are. The OP was asking about other controls.

Well, since I am the OP… :slight_smile: Maybe I should have been more precise. It doesn’t work for native controls on chrome while it does for firefox. And: why did you add a KeyPressed event to the WebDialog class if it doesn’t work by design?

Alex, I updated my project to now show a webDialog and catch the KeyPressed event in it.

https://dl.dropboxusercontent.com/u/17407375/keypressed.xojo_binary_project

The dialog also contains a TextArea and TextField.

On the window as well as in the dialog, keypressed events do get reported correctly under Yosemite 10.10.2 Xojo 2014R3.2 and Chrome 40.0.2214.93 (64-bit).

Could you post a project that demonstrate the issue you describe ?

Michel,

Doesn’t work for me here (for the escape key, at least, which is what I am in need of). Ordinary alphabetical keys do work, though.

[quote=163809:@Alex von Siebenthal]Michel,

Doesn’t work for me here (for the escape key, at least, which is what I am in need of). Ordinary alphabetical keys do work, though.[/quote]

You should have mentioned that you were trying to catch ESC. Indeed it is not reported in Chrome, while it does work in Safari and FireFox.

Why don’t you file a bug report ? That is the best way to have it fixed eventually.

Here is a way to catch keydown in JavaScript that will enable you to detect ESC in the whole page. I have used this to detect arrow keys in Internet Explorer that it does not send.

App.HTML Header :

[code]

[/code]

In the webpage or the dialog :

Sub Shown() ExecuteJavaScript(" $(document).keydown(function(e) { if (e.keyCode == 37 || e.keyCode == 38 || e.keyCode==39 || e.keyCode==40 || e.keyCode==27 )"+_ " { window.location.replace('#'+'kycde'+(e.keyCode));} }) ; ") End Sub

It changes the hashtag with #kycde27 where #kycde is here to signal it is a key, and 27 is ESC. You detect that in Session.HashtagChanged. I left in the JavaScript the keycodes for the arrow keys I used. Just modify it for use.

is it possible to catch key combination? for example “command+s” to fire save method?

You will be able to see Command-S as key code 115, but the browser will catch it, and prompt you to save the page.

On PC the same will occur with Ctrl-S

What you could do is use Ctrl-S on Mac. It generates code 19.

You can see the codes in a TextArea like this :

Sub KeyPressed(Details As REALbasic.KeyEvent) me.text = me.text+str(details.CharCode)+EndOfLine End Sub

Michael B - Your demo project which show the key pressed event firing inside the dialog box actually calls ALL the msgboxes from the main application Keypressed event. the keypressed event in the dialog is not actually firing. I changed the MsgBox in the Dialog key pressed event to be msgbox(“Dialog”) and it always reports the key pressed (from the main form’s Keypressed event). I would like the keypressed logic to launch a routine specific to the dialog box. Whereas the same keys pressed when the dialog box is closed should do something different. I did accomplish this in the past using a flag to tell me which window was open and then coding all the events for both in the main form’s key pressed event. It was more than a little hokey though.

Its been a while. Indeed, the WebPage keypressed is the only one that fires. I do not know if it is a bug for the time being, a seems indeed the best way to go.

But you may not need too much hokey.

  • Add to the Modal master class a property like
WereOpen as Boolean = False
  • In the modal Shown event
WereOpen = True
  • In the modal Shown event
WereOpen = False

Of course if you do need these events in the instance dialog, add the same event definitions and raise them in the above events.

That way all you have to do is test Dialog.WereOpen to know if it is displayed,and consider the keypressed accordingly.