# Buttonclick event - ctrlKey always false

**URL:** https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465
**Category:** Photoshop
**Created:** [February 1, 2024, 2:14pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465 "2024-02-01T14:14:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![morph3us](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/morph3us/32/3099_2.png) [@morph3us](https://forums.creativeclouddeveloper.com/u/morph3us)
#### Post date: [February 1, 2024, 2:14pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465/1 "2024-02-01T14:14:53Z")

</div>

I would like to check wether the control key on the keyboard was pressed while a button was clicked.

```auto
async function main(eventDetails){
    console.log(eventDetails.shiftKey);

document.getElementById("XYZ").addEventListener('click', (event) => { main(event); });

```

This works fine (also with “eventDetails.altKey”). If i exchange it to “ctrlKey”, however, I always get false. I mean, as it generally works, is it a bug? Or am I (again) missing something? If i just console log the event itself, it says the object has a ctrlKey attribute…

I found this, which says its just not working, but nobody else explains why in the thread:

> [@Is there something like ScriptUI's "keyboardState" in UXP?](http://forums.creativeclouddeveloper.com/t/is-there-something-like-scriptuis-keyboardstate-in-uxp/4015/2):
>
> Check Adobe’s Kitchen-sink plugin - it has an example (Alt and Shift are detected, but Ctrl isn’t for some reason)

In the end, the solution just uses “event.ctrlKey”…

---

<div class="post-metadata">

### Author: ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)
#### Post date: [February 1, 2024, 4:17pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465/2 "2024-02-01T16:17:12Z")

</div>

Sometimes it is different for MacOS. They have their own key.

---

<div class="post-metadata">

### Author: ![Wanokuni](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/wanokuni/32/2203_2.png) [@Wanokuni](https://forums.creativeclouddeveloper.com/u/Wanokuni)
#### Post date: [February 1, 2024, 5:49pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465/3 "2024-02-01T17:49:06Z")

</div>

Try this

```auto
    console.log(eventDetails.metaKey || eventDetails.ctrlKey);

```

---

<div class="post-metadata">

### Author: ![morph3us](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/morph3us/32/3099_2.png) [@morph3us](https://forums.creativeclouddeveloper.com/u/morph3us)
#### Post date: [February 1, 2024, 10:09pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465/4 "2024-02-01T22:09:50Z")

</div>

That did the trick, thanks, Wanokuni!

So basically on Windows the control key isnt “ctrlKey”, but the “metaKey”, which I think is very wierd. Shouldnt the “metaKey” rather be the Windows key, which opens the start menu, and “ctrlKey” be the control key on both platforms? (Just a rhetoric question, no need for an answer…)

---

<div class="post-metadata">

### Author: ![Wanokuni](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/wanokuni/32/2203_2.png) [@Wanokuni](https://forums.creativeclouddeveloper.com/u/Wanokuni)
#### Post date: [February 2, 2024, 4:46pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465/5 "2024-02-02T16:46:14Z")

</div>

No, on Windows, the Ctrl key is referred to as the CtrlKey, while on macOS, it is called the Command key (metaKey), which corresponds to the Ctrl key on Windows.

---

<div class="post-metadata">

### Author: ![catte](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/catte/32/3569_2.png) [@catte](https://forums.creativeclouddeveloper.com/u/catte)
#### Post date: [February 7, 2024, 11:43pm UTC](https://forums.creativeclouddeveloper.com/t/buttonclick-event-ctrlkey-always-false/7465/6 "2024-02-07T23:43:58Z")

</div>

the `ctrlKey` part of `ctrlKey || metaKey` is superfluous. on macOS, this property will be true when the ctrl (`^`) key is pressed, which is undesirable. on Windows, this property will always be false; indeed confusingly `metaKey` corresponds to `Ctrl` instead. so if you only want to check for `⌘` on macOS and `Ctrl` on Windows, you should only check for `metaKey`.
