论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash教程
Tag:flash cs,flash 8,鼠绘,as,手绘,工具,文字,loading,入门,初学,mc,影片剪辑,声音,mtv,游戏,引导,遮罩,菜单,补间,广告条,时钟,视频教程

一起学习AS3.0:键盘的操作

文章类别:Flash | 发表日期:2008-9-21 20:13:22

  
键盘的点击与弹起:
/UploadTeach/200708/20070807125320140.swf
Source:        
stage.addEventListener(KeyboardEvent.KEY_DOWN, xKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, xKeyUp);

function xKeyDown(event:KeyboardEvent):void{
        kb.text = "点击"+event.keyCode;
};

function xKeyUp(event:KeyboardEvent):void{
        kb.text = "弹起"+event.keyCode;
};


按键状态的确认:
/UploadTeach/200708/20070807125335422.swf
Source:        
var space_flag:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN,xKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP,xKeyUp);
stage.addEventListener(Event.ENTER_FRAME,xEnterFrame);

function xKeyDown(evt:KeyboardEvent):void{
    if(evt.keyCode == Keyboard.SPACE){
        space_flag = true;
    }
}

function xKeyUp(evt:KeyboardEvent):void{
    if(evt.keyCode == Keyboard.SPACE){
        space_flag = false;
    }
}

function xEnterFrame(evt:Event):void{
    if(space_flag){
                mc.gotoAndStop(2);
        }else{
                mc.gotoAndStop(1);
    }
}                        


键盘的KeyCode表示:
/UploadTeach/200708/20070807125404677.swf
Source:        
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);

function KeyDown(evt:KeyboardEvent){                                                                                                          
        code_text.text                 = String(evt.keyCode);
        location_text.text         = String(evt.keyLocation);
        ctrl_text.text                 = String(evt.ctrlKey);
        shift_text.text                 = String(evt.shiftKey);
        alt_text.text                 = String(evt.altKey);
}


键盘的KeyCode一览

A?Z、0?9键盘KeyCode一览表

keyCode
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90

小键盘的KeyCode

keyCode
0 96
1 97
2 98
3 99
4 100
5 101
6 102
7 103
8 104
9 105
* 106
+ 107
Enter 108
- 109
. 110
/ 111

F1~F15键盘KeyCode

keyCode
F1 112
F2 113
F3 114
F4 115
F5 116
F6 117
F7 118
F8 119
F9 120
F10 121
F11 122
F12 123
F13 124
F14 125
F15 126

其他键的KeyCode

keyCode
BackSpace 8
Tab 9
Clear 12
Enter 13
Shift 16
Ctrl 17
Alt 18
CapsLock 20
Esc 27
Space 32
PageUp 33
PageDown 34
End 35
Home 36
← (左) 37
↑ (上) 38
→ (右) 39
↓ (下) 40
Insert 45
Delete 46
Help 47
NumLock 144
: * 186
; + 187
- = 189
/ ? 191
@ ` 192
[ { 219
\ | 220
] } 221
" ' 222

KeyCode定数一览表:

定数
BackSpace Keyboard.BACKSPACE
CapsLock Keyboard.CAPS_LOCK
Control Keyboard.CONTROL
Delete Keyboard.DELETE
End Keyboard.END
Enter Keyboard.ENTER
Escape Keyboard.ESCAPE
F1 Keyboard.F1
F2 Keyboard.F2
F3 Keyboard.F3
F4 Keyboard.F4
F5 Keyboard.F5
F6 Keyboard.F6
F7 Keyboard.F7
F8 Keyboard.F8
F9 Keyboard.F9
F10 Keyboard.F10
F11 Keyboard.F11
F12 Keyboard.F12
F13 Keyboard.F13
F14 Keyboard.F14
F15 Keyboard.F15
Home Keyboard.HOME
Insert Keyboard.INSERT
NUMPAD 0 Keyboard.NUMPAD_0
NUMPAD 1 Keyboard.NUMPAD_1
NUMPAD 2 Keyboard.NUMPAD_2
NUMPAD 3 Keyboard.NUMPAD_3
NUMPAD 4 Keyboard.NUMPAD_4
NUMPAD 5 Keyboard.NUMPAD_5
NUMPAD 6 Keyboard.NUMPAD_6
NUMPAD 7 Keyboard.NUMPAD_7
NUMPAD 8 Keyboard.NUMPAD_8
NUMPAD 9 Keyboard.NUMPAD_9
NUMPAD + Keyboard.NUMPAD_ADD
NUMPAD . Keyboard.NUMPAD_DECIMAL
NUMPAD / Keyboard.NUMPAD_DIVIDE
NUMPAD Enter Keyboard.NUMPAD_ENTER
NUMPAD * Keyboard.NUMPAD_MULTIPLY
NUMPAD - Keyboard.NUMPAD_SUBTRACT
Page Up Keyboard.PAGE_UP
Page Down Keyboard.PAGE_DOWN
Arrow Up Keyboard.UP
Arrow Down Keyboard.DOWN
Arrow Left Keyboard.LEFT
Arrow Right Keyboard.RIGHT
Shift Keyboard.SHIFT
Space Keyboard.SPACE
Tab Keyboard.TAB
源文件放在附件里面了,应该可以下载。在我的blog不下载也能看到效果。http://www.fastso.org/Lab/keyboard.html  假如有高手偶然误入请指点一二再走~

附件下载:
 keyboard_00_as3.rar
keyboard_01_as3.rar
keyboard_02_as3.rar

进入论坛讨论学习:http://space.flash8.net/bbs/thread-339823-1-3.html

视频教程列表
文章教程搜索
 
Flash推荐教程
Flash热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058