TextInputCanvas Bug?

This may have to be answered by either @Björn_Eiríksson , @Christian_Schmitz or one of the Xojo engineers but please chime in if you have a suggestion.

I’m using @Björn_Eiríksson’s latest build (1.1.2) of the TextInputCanvas plugin in a complex project but the bug I’m seeing is easily reproducible (project attached below).

Essentially, I’m trying to capture the key combination Ctlr / (control and the forward slash key). No matter what I do, I can’t seem to intercept it.

On macOS, I’m using the key combo Cmd / and I intercept that in the DoCommand event of the TextInputCanvas. For some reason, it gets intercepted as a "noop:" command. I capture it like so:

If command = "noop:" Then
  If Keyboard.AsyncCommandKey Then
    ' Command key held down.
    If Keyboard.AsyncKeyDown(&h2C) Then
      ' Cmd-/
    End If
  End If
  Return True
End If

The Ctrl / combo on Windows doesn’t raise a "noop:" command in DoCommand so I have tried to intercept it within TextInputCanvas.KeyDown but to no avail. If you start a new desktop project and drag a TextInputCanvas onto the window and put the following code into the KeyDown event of the canvas you can see from the comments what happens.

If Keyboard.AsyncControlKey Then
  // Works if you press Ctrl-Enter on Windows but not just the control key.
  Break
End If

If Keyboard.AsyncControlKey And Key = "/" Then
  // Never occurs with Ctrl+/
  Break
End If

If Keyboard.AsyncControlKey And Keyboard.AsyncKeyDown(&h2C) Then
  // Also never occurs with Ctrl+/
  Break
End If

If Keyboard.AsyncKeyDown(&h2C) Then
  // Occurs if you press the "/" key but NOT if Ctrl is also held down.
  Break
End If

If Key = "/" Then
  // Occurs if only the "/" key is pressed.
  Break
End If

Essentially, if you hold the Ctrl key down and certain other keys, the event fires (for example Ctrl Enter) but not for others (e.g: Ctrl /). Am I misunderstanding the use of the Keyboard module here?

What’s really odd is I can capture Ctrl Enter on Windows in the KeyDown event but not Ctrl /.

Any ideas?

Binary project
TextInputCanvas 1.1.2 plugin

Am guessing this also happens with the Xojo build of the TextInputCanvas ?

Yes. Well, I’ve just tried Christian’s last release of the plugin and it’s the same.

What’s very weird is you can’t even intercept it with TextInputCanvas.InsertText. You can test if the text to insert is “/” but it doesn’t fire if the Ctrl key is held down.

Feels like an implementation bug to me.

I am not sure I know how to fix that for you.

On Windows I imagine it might be Dialog Key instead of VM_KEYDOWN to get it (not sure though). On Mac I do not know.

It’s not an issue on Mac as I can use DoCommand. Does it seem strange though that Ctrl-Enter is detectable in the KeyDown event but not Ctrl-/?

Norman has the answer for you …

So I sort of figured it out myself (or at least what seems to be a robust workaround).

I was trying to call a private method (ToggleCommenting) internally within the TextInputCanvas when Ctrl-/ occurs. I decided to just make that a public method and add a menu handler to the parent window. Now Ctrl-/ is intercepted by the menubar and I can call the public method.

Weird why Ctrl is not being captured but the workaround at least works.