简体   繁体   English

游戏的Silverlight按键事件

[英]Silverlight keydown event for games

I'm trying to use the key down event in silverlight for a game I'm working on. 我正在尝试将Silverlight中的key down事件用于正在开发的游戏。 The problem I'm having is that silverlight treats keydown like windows does. 我遇到的问题是Silverlight像Windows一样对待keydown。 For example if you hold down the left arrow key the keydown event triggers once, then pauses for a short while before triggering repeatedly. 例如,如果按住左箭头键,则keydown事件将触发一次,然后暂停一会儿,然后重复触发。

Obviously in a game this won't do since a player expects to be able to hold a key down to repeat an action without a pause in event. 显然,在游戏中这是不会做的,因为玩家希望能够按住键来重复操作而不会在事件中暂停。

So how do I get key down events constantly without the brief pause between the first key down event and the following repeated events? 那么,如何在第一个按键事件和随后的重复事件之间没有短暂停顿的情况下,不断获得按键事件呢?

I believe it only repeats the KeyDown and not the KeyUp, so you would need to track the state of previous KeyUp events yourself to determine if the key was/is already pressed . 我相信它只会重复KeyDown而不是KeyUp, 因此您需要自己跟踪以前的KeyUp事件的状态,以确定该键是否已被按下

Keyboard support for games in Silverlight is not great (eg does not allow for multiple simultaneous keys). Silverlight中游戏的键盘支持不是很好(例如,不允许同时使用多个键)。 You really want the ability to ask if certain keys are pressed (like the old scan-keycode system), but that is not a browser-friendly thing. 您确实希望能够询问是否按下了某些键(例如旧的扫描键码系统),但这不是浏览器友好的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM