为什么使用event.keyCdoe会出错, hint : "event" is undefined

yoyo8000 2004-10-21 03:50:08
rt
...全文
240 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yoyo8000 2004-10-21
  • 打赏
  • 举报
回复
那怎么办呢? 我只想要这个SCRIPT操作我的程序. 做个测试而已.
我想做压力测试,让程序不停的做,一直到它接收到ESC的键值就停止.
ttyp 2004-10-21
  • 打赏
  • 举报
回复
不能直接定义在script里,那时候还没创建event对象呢
yoyo8000 2004-10-21
  • 打赏
  • 举报
回复
IE6.0 + xpsp1
OS: Winxp
yoyo8000 2004-10-21
  • 打赏
  • 举报
回复
//This script will send KeyScheme1 to the active window.
var Keys = new Array;
var LT = 0;
var RT = 1;
var UP = 2;
var DN = 3;
var EN = 4;
var BK = 5;
var AL1 = 6;
var AL2 = 7;
var AL3 = 8;

var N = 9;
var J = 10;
var R = 11;
var M = 12;
var P = 13;
var TA = 14;


Keys[LT] = "{LEFT}";
Keys[RT] = "{RIGHT}";
Keys[UP] = "{UP}";
Keys[DN] = "{DOWN}";
Keys[EN] = "{ENTER}";
Keys[BK] = "{BKSP}";
Keys[AL1] = "%+{f}";
Keys[AL2] = "%+{r}";
Keys[AL3] = "%+{c}";

Keys[N] = "{n}";
Keys[J] = "{j}";
Keys[R] = "{r}";
Keys[M] = "{m}";
Keys[P] = "{p}";
Keys[TA] = "{TAB}";

//---------
var whichCode = event.keyCode;
//--------

var JumboCommand = new Array;
var DrawFillBox = new Array;
var InputRemotingCommand = new Array;
var MediaControl = new Array;
var KeyScheme1 = new Array;

function RunKeyScheme( keyScheme, delay )
{
for( i = 0; i < keyScheme.length; i++ )
{

WScript.Sleep( 10);
shell.SendKeys( Keys[keyScheme[i]] );
WScript.Sleep( delay );
}


}// function RunKeyScheme



var shell = WScript.CreateObject("WScript.Shell");



WScript.Echo("Activate the RUI Client Window, Key will be sent to that window!.");

WScript.Echo("Action!");

while (whichCode != 0x1b)
{
//--------------------------------------------------------test 640*480
TestJumboCommand ();
TestDrawFillBox();
TestSinaConnection();
TestInputRemotingCommand();
TestMediaControl();
TestDigitalHome_fork();
TestDigitalHome_nonfork();


//--------------------------------------------------------test 800*600
shell.SendKeys("%+{r}");
shell.SendKeys("{DOWN}");
shell.SendKeys("{ENTER}");
TestJumboCommand ();
TestDrawFillBox();
TestSinaConnection();
TestInputRemotingCommand();
TestMediaControl();
TestDigitalHome_nonfork();
TestDigitalHome_fork();

//--------------------------------------------------------test 1024*768
shell.SendKeys("%+{r}");
shell.SendKeys("{DOWN}");
shell.SendKeys("{DOWN}");
shell.SendKeys("{ENTER}");
TestJumboCommand ();
TestDrawFillBox();
TestSinaConnection();
TestInputRemotingCommand();
TestMediaControl();
TestDigitalHome_nonfork();
TestDigitalHome_fork();

//--------------------------------------------------------test Fullscreen
shell.SendKeys("%+{r}");
shell.SendKeys("{DOWN}");
shell.SendKeys("{DOWN}");
shell.SendKeys("{DOWN}");
shell.SendKeys("{ENTER}");
TestJumboCommand ();
TestDrawFillBox();
TestSinaConnection();
TestInputRemotingCommand();
TestMediaControl();
TestDigitalHome_nonfork();
TestDigitalHome_fork();
}
WScript.Echo( "End!");
WScript.Quit();


//---------------------------------------------------------
function TestJumboCommand ()
{

// first connection: JUMBO command
JumboCommand[0] = AL3;
JumboCommand[1] = UP;
JumboCommand[2] = EN;
JumboCommand[3] = EN;
JumboCommand[4] = EN;

RunKeyScheme( JumboCommand, 800 );
}//function TestJumboCommand

function TestDrawFillBox()
{

//Draw Fill Box
DrawFillBox[0] = AL3;
DrawFillBox[1] = EN;
DrawFillBox[2] = EN;
DrawFillBox[3] = EN;
DrawFillBox[4] = EN;
DrawFillBox[5] = EN;

RunKeyScheme( DrawFillBox, 800 );
shell.SendKeys("+");
shell.SendKeys("+");
shell.SendKeys("+");
WScript.Sleep( 500);
shell.SendKeys("-");
shell.SendKeys("-");
shell.SendKeys("-");
}//function TestDrawFillBox

function TestSinaConnection()
{

shell.SendKeys("%+{c}");
WScript.Sleep(500);
shell.SendKeys("{UP}");
WScript.Sleep(500);
shell.SendKeys("{UP}");
WScript.Sleep(500);
shell.SendKeys("{ENTER}");
WScript.Sleep(500);

}//function TestSinaConnection()


function TestInputRemotingCommand()
{

//Input remoting command
InputRemotingCommand[0] = AL3;
InputRemotingCommand[1] = DN;
InputRemotingCommand[2] = DN;
InputRemotingCommand[3] = DN;
InputRemotingCommand[4] = DN;
InputRemotingCommand[5] = EN;
InputRemotingCommand[6] = N;
InputRemotingCommand[7] = J;
InputRemotingCommand[8] = R;
InputRemotingCommand[9] = M;
InputRemotingCommand[10] = P;

RunKeyScheme( InputRemotingCommand, 800 );
}//function TestInputRemotingCommand

function TestMediaControl()
{

//Media control
MediaControl[0] = AL3;
MediaControl[1] = DN;
MediaControl[2] = DN;
MediaControl[3] = EN;

RunKeyScheme( MediaControl, 800 )

MediaTesting();
// test disconnect current connection
shell.SendKeys("%+{f}");
WScript.Sleep( 500);
shell.SendKeys("{ENTER}");
WScript.Sleep( 500);
//test disconnect all connections
shell.SendKeys("%+{f}");
WScript.Sleep( 500);
shell.SendKeys("{DOWN}");
WScript.Sleep( 500);
shell.SendKeys("{ENTER}");
WScript.Sleep( 500);
}//function TestMediaControl

function TestDigitalHome_fork()
{

//Digital Home fork
shell.SendKeys("%+{c}");
WScript.Sleep( 500);
shell.SendKeys("{DOWN}");
WScript.Sleep( 500);
shell.SendKeys("{ENTER}");
WScript.Sleep( 500);
shell.SendKeys("{ENTER}");
WScript.Sleep( 1500);

MediaTesting();


}//function TestDigitalHome_fork()


function TestDigitalHome_nonfork()
{

//Digital Home* non-fork
shell.SendKeys("%+{c}");
WScript.Sleep( 500);
shell.SendKeys("{DOWN}");
WScript.Sleep( 500);
shell.SendKeys("{DOWN}");
WScript.Sleep( 500);
shell.SendKeys("{DOWN}");
WScript.Sleep( 500);
shell.SendKeys("{ENTER}");
WScript.Sleep( 500);
shell.SendKeys("{ENTER}");
WScript.Sleep( 1500);

MediaTesting();
}//function TestDigitalHome_nonfork()


function MediaTesting()
{

// PLAY VIDEO
//speed play
KeyScheme1[0] = RT;
KeyScheme1[1] = EN;
//forward
KeyScheme1[2] = RT;
KeyScheme1[3] = EN;
//back
KeyScheme1[4] = RT;
KeyScheme1[5] = EN;
//fragment forward
KeyScheme1[6] = RT;
KeyScheme1[7] = EN;
//fragment back
KeyScheme1[8] = RT;
KeyScheme1[9] = EN;
//*
KeyScheme1[10] = RT;
KeyScheme1[11] = EN;
//+
KeyScheme1[12] = RT;
KeyScheme1[13] = EN;
//-
KeyScheme1[14] = RT;
KeyScheme1[15] = EN;
//end
KeyScheme1[16] = RT;
KeyScheme1[17] = EN;
//pause
KeyScheme1[18] = RT;
KeyScheme1[19] = RT;
KeyScheme1[20] = EN;
KeyScheme1[21] = LT;
KeyScheme1[22] = EN;
KeyScheme1[23] = LT;
KeyScheme1[24] = EN;
//back to main menu
KeyScheme1[25] = TA;
KeyScheme1[26] = EN;
KeyScheme1[27] = DN;
KeyScheme1[28] = EN;

//DISPLAY PICTURE
//display
KeyScheme1[29] = RT;
KeyScheme1[30] = EN;
//forward
KeyScheme1[31] = RT;
KeyScheme1[32] = EN;
KeyScheme1[33] = EN;
//back
KeyScheme1[34] = RT;
KeyScheme1[35] = EN;
//back to main menu
KeyScheme1[36] = LT;
KeyScheme1[37] = EN;
KeyScheme1[38] = LT;
KeyScheme1[39] = LT;
KeyScheme1[40] = EN;
KeyScheme1[41] = DN;
KeyScheme1[42] = DN;
KeyScheme1[43] = EN;

//PLAY MUSIC
//display
KeyScheme1[44] = RT;
KeyScheme1[45] = EN;

//pause
KeyScheme1[46] = RT;
KeyScheme1[47] = EN;
//forward
KeyScheme1[48] = RT;
KeyScheme1[49] = EN;
//back
KeyScheme1[50] = RT;
KeyScheme1[51] = EN;
//back to main menu
KeyScheme1[52] = RT;
KeyScheme1[53] = EN;
KeyScheme1[54] = DN;
KeyScheme1[55] = DN;
KeyScheme1[56] = DN;
KeyScheme1[57] = EN;

//MEDIAL CONTROL
KeyScheme1[58] = BK;

//ADAPTTER SETTING
KeyScheme1[59] = DN;
KeyScheme1[60] = DN;
KeyScheme1[61] = DN;
KeyScheme1[62] = DN;
KeyScheme1[63] = EN;
KeyScheme1[64] = BK;

RunKeyScheme( KeyScheme1, 500 );


}//function MediaTesting

ttyp 2004-10-21
  • 打赏
  • 举报
回复
IE6.0 + WIN2K 测试通过
----------------------------------
<body onkeyup="alert(event.keyCode);">

你什么浏览器啊
libra_king 2004-10-21
  • 打赏
  • 举报
回复
show your code!
yoyo8000 2004-10-21
  • 打赏
  • 举报
回复
sorry for wrong typing.

I type 'event.keyCode' in program. When i try to run the script, the error message is 'event is undefined'.

Thanks a lot.
ttyp 2004-10-21
  • 打赏
  • 举报
回复
event.keyCode

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧