/**
* Copyright itou_hiroki ( http://wonderfl.net/user/itou_hiroki )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9nLS
*/
// キーボード横幅は 数字段で、15個。
// (画面横幅pixel)465÷15=31 余白を考えて1key 30pxで使う
// 30px = 余白2px + key 28px
//
package {
import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
import flash.text.*;
[SWF(width="465",height="465",backgroundColor="0xeeeeee",frameRate="60")]
public class FlashTest extends Sprite {
private var keyCode_to_charCodeJP:Array = new Array();
private var keyImages:Array = new Array();
private var last:int;
private var xoff:int;
private var yoff:int;
public function FlashTest() {
// write as3 code here..
//http://livedocs.adobe.com/flex/3_jp/langref/flash/events/KeyboardEvent.html
//数字の段
xoff = 2;
yoff = 2;
for (var i:uint=0; i<15; i++) {
keyImages[i] = new Sprite();
make_key_image(keyImages[i], i*30+xoff,yoff, 28);
addChild(keyImages[i]);
}
last = i;
yoff = 32;
{//Tab
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15);
addChild(keyImages[i]);
i++;
}
last = i;
xoff = 15+2+30;
//QWERTYの段
for (; i<last+12; i++) {
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28);
addChild(keyImages[i]);
}
last = i;
xoff = 2;
yoff = 62;
{//Eisuu
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15+7);
addChild(keyImages[i]);
i++;
}
last = i;
xoff = 15+8+2+30;
//ASDFの段
for (; i<last+12; i++) {
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28);
addChild(keyImages[i]);
}
last = i;
{//Enter
keyImages[i] = new Sprite();
yoff = 32;
xoff = 15+8+2+30+ (i-last)*30;
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15);
yoff = 62;
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+8);
keyImages[i].graphics.lineStyle(1,0x666666);
keyImages[i].graphics.beginFill(0x666666,1);
keyImages[i].graphics.drawRect(x,y, w,28, 3);
keyImages[i].graphics.endFill();
addChild(keyImages[i]);
i++;
}
last = i;
xoff = 2;
yoff = 92;
{//Shift
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15+7+15);
xoff = 400;
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15+7);
addChild(keyImages[i]);
i++;
}
last = i;
xoff = 15+8+15+2+30;
//ZXCVの段
for (; i<last+11; i++) {
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28);
addChild(keyImages[i]);
}
last = i;
xoff = 2;
yoff = 122;
{//Ctrl
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15+7);
addChild(keyImages[i]);
i++;
}
last = i;
xoff = 118;
{//NoConvert
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15);
addChild(keyImages[i]);
i++;
}
last = i;
xoff += 30+15;
{//Space
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 68);
addChild(keyImages[i]);
i++;
}
last = i;
xoff += 70;
{//Convert
keyImages[i] = new Sprite();
make_key_image(keyImages[i], (i-last)*30+xoff,yoff, 28+15);
addChild(keyImages[i]);
i++;
}
}
private function add_text_style(tfd:TextField):void {
var tfm:TextFormat = new TextFormat();
tfm.font = "Verdana";
tfm.size = 18;
tfm.color = 0x000033;
tfd.autoSize = TextFieldAutoSize.LEFT;
tfd.defaultTextFormat = tfm;
}
private function make_japanese_keyboard_code():void {
var keys:String = '';
keys = '229 49 50 51 52 53 54 55 56 57 48 189 222 220 8 ';
keys += '9 81 87 69 82 84 89 85 73 79 80 192 219 ';
keys += '20 65 83 68 70 71 72 74 75 76 187 186 221 13 ';
keys += '16 90 88 67 86 66 78 77 188 190 191 226 ';
keys += '17 29 32 28'
var keyCodes:Array = keys.split(' ');
keys = 'HanZen Num1 Num2 Num3 Num4 Num5 Num6 Num7 Num8 Num9 Num0 Minus Accent Yen BackSpace ';
keys += 'Tab Q W E R T Y U I O P AtMark LeftBracket ';
keys += 'Eisuu A S D F G H J K L SemiColon Colon RightBracket Enter ';
keys += 'Shift Z X C V B N M Comma Period Slash Backslash ';
keys += 'Ctrl NoConvert Space Convert';
var charCodeJP:Array = keys.split(' ');
for (var i:int=0; i<keyCodes.length; i++) {
keyCode_to_charCodeJP[keyCodes[i]] = charCodeJP[i];
}
}
public function make_key_image(obj:Sprite, x:int,y:int, w:int):void {
//http://livedocs.adobe.com/flex/3_jp/langref/flash/display/Graphics.html
obj.graphics.lineStyle(1,0x000000);
obj.graphics.beginFill(0x666666,1);
obj.graphics.drawRoundRect(x,y, w,28, 3);
obj.graphics.endFill();
}
}
}