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.
/// <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" },
])
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.