# If Keyboard.CommandKey

**URL:** <https://forum.xojo.com/t/if-keyboard-commandkey/88968>\
**Category:** General\
**Created:** [October 6, 2026, 8:04am UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968 "2026-10-06T08:04:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klemens\_Klarhoelter](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@Klemens\_Klarhoelter](https://forum.xojo.com/u/Klemens_Klarhoelter)\
**Post date:** [October 6, 2026, 8:04am UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968/1 "2026-10-06T08:04:25Z")

</div>

Why can’t I intercept keys like “Command” or “Control” in a textarea using the KeyDown or KeyUp events? Other keys, such as a–z, work fine.

This code doesn’t work:

Function KeyDown(key As String) As Boolean Handles KeyDown #If TargetMacOS Then // Prüfen, ob Cmd + V gedrückt wurde If Keyboard.CommandKey And (key = “v” Or key = “V”) Then // Deine eigene Logik hier einfügen… Return True // True verhindert das Standard-Einfügen durch das System End If #Else // Prüfen, ob Strg + V gedrückt wurde If Keyboard.ControlKey And (key = “v” Or key = “V”) Then // Deine eigene Logik hier einfügen… Return True // True verhindert das Standard-Einfügen durch das System End If #EndIf // Standardverhalten für alle anderen Tasten beibehalten Return False End Function

---

<div class="post-metadata">

**Author:** ![Christian\_Wheel](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_wheel/32/20536_2.png) [@Christian\_Wheel](https://forum.xojo.com/u/Christian_Wheel)\
**Post date:** [October 6, 2026, 8:50am UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968/2 "2026-10-06T08:50:55Z")

</div>

The framework doesn’t report modifier keys as keypresses the same way.

You need to poll periodically using a timer, check for Keyboard.AsyncCommandKey or Keyboard.AsyncControlKey to be true.

If you’re trying to add keyboard shortcuts to your textarea (for example Cmd+B to change to bold text), you can use the KeyDown or KeyUp events to check for the “B” key, then also test Keyboard.AsyncCommandKey and if it’s true, you’ve got a Cmd+B that was pressed.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [October 6, 2026, 11:03am UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968/3 "2026-10-06T11:03:28Z")

</div>

```auto
Function KeyDown(key As String) As Boolean Handles KeyDown
#If TargetMacOS Then
// Prüfen, ob Cmd + V gedrückt wurde
If Keyboard.CommandKey And (key = "v" Or key = "V") Then
// Deine eigene Logik hier einfügen…
Return True
// True verhindert das Standard-Einfügen durch das System
End If
#Else
// Prüfen, ob Strg + V gedrückt wurde
If Keyboard.ControlKey And (key = "v" Or key = “V”) Then
// Deine eigene Logik hier einfügen…
Return True
// True verhindert das Standard-Einfügen durch das System
End If
#EndIf
// Standardverhalten für alle anderen Tasten beibehalten
Return False
End FunctionaPreformatted text

```

This is better for reading.

Now the question:  
How do you know this code works or not ? 😉

The command was intercepted by the OS.  
And you can see that by yourself if you place text in the Clipboard.

AI suggestion #1 does not works too, but this line is… nice:

`If Keyboard.AsyncCommandKey And key.Lowercase = "v" Then`

Only one test for both **V** and **v** 😉

“These said”, what do you want to do with Cmd-v ?

WHY DON’T YOU ADD A NEW MENUHANDLER with Cmd-Shift-V or | and Alt-Shift-V ?

---

<div class="post-metadata">

**Author:** ![Klemens\_Klarhoelter](https://forum.xojo.com/letter_avatar_proxy/v4/letter/k/ecccb3/32.png) [@Klemens\_Klarhoelter](https://forum.xojo.com/u/Klemens_Klarhoelter)\
**Post date:** [October 6, 2026, 1:13pm UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968/4 "2026-10-06T13:13:11Z")

</div>

And that’s exactly what isn’t working—is this a Xojo bug?

---

<div class="post-metadata">

**Author:** ![Eric\_Williams](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@Eric\_Williams](https://forum.xojo.com/u/Eric_Williams)\
**Post date:** [October 6, 2026, 2:45pm UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968/5 "2026-10-06T14:45:28Z")

</div>

One reason it might not be working is that Command V is the menu shortcut for Paste and the menu is handling the keystroke before the text area sees it.

---

<div class="post-metadata">

**Author:** ![Jared\_Feder](https://forum.xojo.com/user_avatar/forum.xojo.com/jared_feder/32/3036_2.png) [@Jared\_Feder](https://forum.xojo.com/u/Jared_Feder)\
**Post date:** [October 6, 2026, 3:37pm UTC](https://forum.xojo.com/t/if-keyboard-commandkey/88968/6 "2026-10-06T15:37:48Z")

</div>

If you just want to intercept the default paste functionality, you can subclass the `TextArea` and then add a menu handler for `EditPaste`.

From there, you can do whatever you want and then return `True` to stop the default paste functionality from happening or return `False` to allow the paste.

 ![Screenshot 2026-10-06 at 10.35.37 AM](https://forum.xojo.com/uploads/default/original/3X/d/2/d294910eb1c5a97ce8489571b6e5dec2014287d0.png)
