Detect Control Key In Text area

Using windows 11 I want to insert the current date and time into a text field on detection of Ctrl-t keypress. As far as I can tell the following code should work but does not. The text area is not read only, ‘t’ alone works, but Ctrl-t elicits nothing. What am I missing? This is the key down event of the control.

if key=“t” and Keyboard.ControlKey then

var d as string =DateTime.Now.SQLDateTime
me.AddText(d)
return true

else

return false
end if

Control-T is trapped as a Control value (below ASCII 32) value.
I reversed your initial If contents to:

if key=“t” and Keyboard.ControlKey then

get the same result, then I splitted it to:

if  Keyboard.ControlKey then
Beep
If key=“t” Then
System.DebugLog "t key pressed"

I get the beep, but nothing in the debug part then I realized that key = “t” cannot works
key = $14 (Decimal 20) in that case.

So replace key = "t" with key = chr(20) and it works at least on macOS.

Another option would be to have a menu item with that combination (control-T) which inserts the date.

3 Likes

Thanks for the suggestions, this one works for now and is here for reference, the menu addition also a good idea should I wish to add further options down the line.

if Keyboard.ControlKey and key=chr(20) then

var d as string = DateTime.Now.SQLDateTime
me.AddText(d)
return true

else

return false
end if

Note: you don’t need to test Keyboard.ControlKey. You can’t get chr(20) without pressing the control key, so

if key=chr(20) then

is sufficient.

3 Likes

I like your basic logic (no need to test the Control-Key…)
I needed to test the Control Key, then I tested what value Key As String is in the Debugger… Then, and only then, I tested Chr(20).