# How to register a keyboard shortcut

**URL:** <https://uzu.lurk.org/t/how-to-register-a-keyboard-shortcut/5957>\
**Category:** Strudel\
**Tags:** questions\
**Created:** [7 October 2025 20:50 UTC](https://uzu.lurk.org/t/how-to-register-a-keyboard-shortcut/5957 "2025-10-07T20:50:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![firolightfog](https://uzu.lurk.org/user_avatar/uzu.lurk.org/firolightfog/32/3305_2.png) [@firolightfog](https://uzu.lurk.org/u/firolightfog)\
**Post date:** [7 October 2025 20:50 UTC](https://uzu.lurk.org/t/how-to-register-a-keyboard-shortcut/5957/1 "2025-10-07T20:50:35Z")

</div>

I’m not sure if there’s a simple way to do this but the code below doesn’t work for sure. Any idea how to fix it?

```javascript
let myInteger=5
keyboard('ctrl+i', () => {myInteger = Math.floor(Math.random()*12)})

```

---

<div class="post-metadata">

**Author:** ![firolightfog](https://uzu.lurk.org/user_avatar/uzu.lurk.org/firolightfog/32/3305_2.png) [@firolightfog](https://uzu.lurk.org/u/firolightfog)\
**Post date:** [17 October 2025 12:27 UTC](https://uzu.lurk.org/t/how-to-register-a-keyboard-shortcut/5957/2 "2025-10-17T12:27:34Z")

</div>

The solution will be whenKey()

But not sure about the details yet. The code below works but pressing the key, the integer is changed _temporarily_ only. It is not exactly what I want. I want permanent change.

```javascript
let myint="1".whenKey("Control:i", x=>x.set(irand(16)))
$: s("bd:6").euclid(myint,16) 

```

---

<div class="post-metadata">

**Author:** ![firolightfog](https://uzu.lurk.org/user_avatar/uzu.lurk.org/firolightfog/32/3305_2.png) [@firolightfog](https://uzu.lurk.org/u/firolightfog)\
**Post date:** [25 November 2025 11:24 UTC](https://uzu.lurk.org/t/how-to-register-a-keyboard-shortcut/5957/3 "2025-11-25T11:24:02Z")

</div>

Related Discord thread: [Why are there no persistent variables in web strudel?](https://discord.com/channels/779427371270275082/1442641813184708718)
