# How to change special shortcut via extension?

**URL:** <https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135>\
**Category:** Questions\
**Created:** [April 23, 2023, 9:56am UTC](https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135 "2023-04-23T09:56:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankisme](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@ankisme](https://discourse.mapeditor.org/u/ankisme)\
**Post date:** [April 23, 2023, 9:56am UTC](https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135/1 "2023-04-23T09:56:26Z")

</div>

Current shorcut of dragging map is [Space + Left Mouse Button], and I really don’t like this shortcut, because when I use the shortcut, space always do the wrong thing, such as toggle the visible of current layer, and the space is not easy to press, because it’s a big and long key in the keyboard.

So I want to use [Ctrl + Left Mouse Button] to instead [Space + Left Mouse Button], but I could not found any way to do this in Preferenced.

Now I want to use a tiled.registerTool or tiled.registerAction to do this, but how could I finish the script?

My thought is, when I pressing the space key, then I also pressing the ctrl key.

```typescript
/// <reference types="@mapeditor/tiled-api" />

/* global tiled */

const dragLayer = tiled.registerAction("DragLayer", function (/* action */) {
	tiled.alert(`My desired shortcut is pressing [Ctrl + Left Mounse Button] to drag map,

	but current shortcut is pressing [Space + Left Mouse Button], and how to do it?`)
})
dragLayer.text = "DragLayer"
dragLayer.shortcut = "Space"

tiled.extendMenu("Layer", [
	{ action: "DragLayer", before: "SelectPreviousLayer" },
])

```

---

<div class="post-metadata">

**Author:** ![ankisme](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@ankisme](https://discourse.mapeditor.org/u/ankisme)\
**Post date:** [April 23, 2023, 9:58am UTC](https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135/2 "2023-04-23T09:58:29Z")

</div>

And I don’t want to use Middle Mouse Button too.

---

<div class="post-metadata">

**Author:** ![eishiya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.mapeditor.org/eishiya/32/2534_2.png) [@eishiya](https://discourse.mapeditor.org/u/eishiya)\
**Post date:** [April 23, 2023, 1:59pm UTC](https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135/3 "2023-04-23T13:59:50Z")

</div>

You can’t change the default shortcut for this as it’s hard-coded, and Actions are one-time things, they cannot be used to implement dragging behaviour. So, what you’re trying to do is not possible via scripting; you would have to modify Tiled itself.

Scripted _Tools_ can implement dragging behaviour because they can react to mouse movement and click events, but you’d have to switch to the tool to pan, it’s not something you’d do with a modifier.

---

<div class="post-metadata">

**Author:** ![ankisme](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@ankisme](https://discourse.mapeditor.org/u/ankisme)\
**Post date:** [April 23, 2023, 2:21pm UTC](https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135/4 "2023-04-23T14:21:31Z")

</div>

OK, I see. Change this shortcut by script seems not convient, maybe recompile c++ code is better.

Thank you for replying.

---

<div class="post-metadata">

**Author:** ![ankisme](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@ankisme](https://discourse.mapeditor.org/u/ankisme)\
**Post date:** [April 24, 2023, 7:08am UTC](https://discourse.mapeditor.org/t/how-to-change-special-shortcut-via-extension/6135/5 "2023-04-24T07:08:28Z")

</div>

Finally I use AutoHotKey to solve the problem, now I can use [Ctrl+LeftMouseButon] to dragging and also [Ctrl+Mouse Wheel] to zoom in and zoom out.

I think it is much more better than [Space+LeftMouseButon] and [Ctrl+Mouse Wheel], and it also could fix the bug I found (in [Issue #3672](https://github.com/mapeditor/tiled/issues/3672))

Here is the AutoHotKey script

```auto
#IfWinActive ahk_exe tiled.exe
~LCtrl::
KeyWait, LButton, Down
SendInput , {Space Down}
KeyWait, LCtrl, U
SendInput , {Space Up}
return
#IfWinActive

```
