[原创]KeyBoardUtil 键盘键值对应类

本文介绍了一个名为KeyBoardUtil的类,该类用于在Flash环境中实现键盘按键与字符代码之间的映射。通过注册常见的ASCII字符及其对应的键盘输入值,使得开发者能够方便地获取和设置键盘输入。此外,还提供了释放资源的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


package cn.qicool.game.wx2.bundle.fastkey.utils
{
import flash.utils.Dictionary;

public class KeyBoardUtil
{
public function KeyBoardUtil()
{
_keyDict = new Dictionary();
_charDict = new Dictionary();

registerAllKeys();
}

public function getCharCode(key:uint):String
{
return _keyDict[key] as String;
}

public function getKeyCode(charCode:String):uint
{
return _charDict[charCode] as uint;
}


private function registerAllKeys():void
{
registerKey(65, "A");
registerKey(66, "B");
registerKey(67, "C");
registerKey(68, "D");
registerKey(69, "E");
registerKey(70, "F");
registerKey(71, "G");
registerKey(72, "H");
registerKey(73, "I");
registerKey(74, "J");
registerKey(75, "K");
registerKey(76, "L");
registerKey(77, "M");
registerKey(78, "N");
registerKey(79, "O");
registerKey(80, "P");
registerKey(81, "Q");
registerKey(82, "R");
registerKey(83, "S");
registerKey(84, "T");
registerKey(85, "U");
registerKey(86, "V");
registerKey(87, "W");
registerKey(88, "X");
registerKey(89, "Y");
registerKey(90, "Z");
registerKey(13, "ENTER");
registerKey(9, "TAB");
registerKey(192, "~");
registerKey(219, "[");
registerKey(48, "0");
registerKey(49, "1");
registerKey(50, "2");
registerKey(51, "3");
registerKey(52, "4");
registerKey(53, "5");
registerKey(54, "6");
registerKey(55, "7");
registerKey(56, "8");
registerKey(57, "9");
}

private function registerKey(key:uint, charCode:String):void
{
_keyDict[key] = charCode;
_charDict[charCode] = key;
}


public function dispose():void
{
_charDict = null;
_keyDict = null;
}

private var _charDict:Dictionary;
private var _keyDict:Dictionary;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值