检测自定义键盘输入事件并做出反应
Detect and react to custom keyboard input events
我应该如何收听 A 或 Alt+[=17= 的按键、按键和按键]A?
分别来自 ScreenSpaceEventHandler(element).setInputAction(action, type, modifier), it follows that type
and modifier
must be of types ScreenSpaceEventType and KeyboardEventModifier 的文档,这相当于一组相当有限的事件可供我使用。
ScreenSpaceEventHandler
仅适用于涉及屏幕的输入事件space:鼠标、触摸和指针事件。对于像 ALT + A 这样的原始键盘事件,只需使用 JavaScript native keyboard events such as keydown
, keypress
等。你不需要Cesium 帮助接收这些事件。
但是,您需要将 tabindex
应用到 Cesium canvas,以使其能够接收输入焦点:
var viewer = new Cesium.Viewer('cesiumContainer');
var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
您可以在 Cesium Camera Tutorial 中找到完整的工作示例。单击地球本身,然后使用 W、A、S、 D移动相机。
我应该如何收听 A 或 Alt+[=17= 的按键、按键和按键]A?
分别来自 ScreenSpaceEventHandler(element).setInputAction(action, type, modifier), it follows that type
and modifier
must be of types ScreenSpaceEventType and KeyboardEventModifier 的文档,这相当于一组相当有限的事件可供我使用。
ScreenSpaceEventHandler
仅适用于涉及屏幕的输入事件space:鼠标、触摸和指针事件。对于像 ALT + A 这样的原始键盘事件,只需使用 JavaScript native keyboard events such as keydown
, keypress
等。你不需要Cesium 帮助接收这些事件。
但是,您需要将 tabindex
应用到 Cesium canvas,以使其能够接收输入焦点:
var viewer = new Cesium.Viewer('cesiumContainer');
var canvas = viewer.canvas;
canvas.setAttribute('tabindex', '0'); // needed to put focus on the canvas
您可以在 Cesium Camera Tutorial 中找到完整的工作示例。单击地球本身,然后使用 W、A、S、 D移动相机。