键盘事件和死信 [英] keyboard events and dead letters

查看:54
本文介绍了键盘事件和死信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找一个字符被按下的东西,在输入框上使用带有

死信的重音,例如á。


我已经制作了一个小程序来检查keydown键盘事件,

按键和键盘,并且只有两次被触发的
键盘。第一个带有0个键码和

特征代码。没有keydown或keypress事件,并且它没有足够的信息来了解真正按下了什么字符。

它发生在Linux上的Firefox 2.0.0.14。 Windows上的Firefox工作原理

并且行为方式不同。


输入框已正确修改,因此,我猜Firefox了解

无论什么键序列

从操作系统或X系统接收。


有什么建议吗?


由于事先

解决方案
华金ZUAZO在comp.lang.javascript于2008年18味写的 的:


我正试图在输入框上使用带有

死信(例如*)的重音来查找按下的字符。


我做了一个小程序来检查键盘事件keydown,

按键和键盘,只有

键盘一个是开了两次。第一个带有0个键码和

特征代码。没有keydown或keypress事件,并且它没有足够的信息来了解真正按下了什么字符。

它发生在Linux上的Firefox 2.0.0.14。 Windows上的Firefox工作原理

并且行为方式不同。


输入框已正确修改,因此,我猜Firefox了解

无论是什么键序列

从操作系统或X系统接收。


有什么建议吗?



为什么不将每个密钥的整个内容与之前的内容进行比较?


-

Evertjan。

荷兰。

(请在我的电子邮件地址中将x'变为点数)


< blockquote> Thomas''PointedEars''Lahn写道:


var charCode =(typeof e.charCode!=" undefined"

? e.charCode

:( typeof e.keyCode!=" undefined"

?e.keyCode

:charCode);



:charCode));


18 mayo,11:52,Thomas''PointedEars''Lahn< PointedE ... @ web.de>

写道:


Thomas''PointedEars''Lahn写道:


var charCode =(typeof e.charCode!=" undefined"

? e.charCode

:( typeof e.keyCode!=" undefined"

?e.keyCode

:charCode);



:charCode));



这是html测试页面:


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN">


< html>

<! - 键盘事件测试程序,作者:JoaquínZuazo - >

< head>

< title>测试键盘事件< / title>

< meta http-equiv =" encoding = UTF-8">< / meta>


window.onload = testkeys;

var checkinput,out;

var title =" Event\t\tkeyCode\t\twhich\t\tcharCode\tfromCharCo德

\tInput Box\\\
\\\
英寸;


函数testkeys()

{

checkinput = document.getElementById(" checkinput");

out = document。 getElementById(" out");

out.innerHTML = title;

checkinput.onkeydown = check_down;

checkinput.onkeypress = check_press;

checkinput.onkeyup = check_up;

}

function reset_all()

{

out.innerHTML = title;

checkinput.value ="" ;;


}

函数output_message(function_name ,事件)

{

var valid_one = event.keyCode? event.keyCode:event.which?

event.which:event.charCode;

var message = function_name +" \t"

+(event.keyCode?event.keyCode:event.keyCode == 0?

0:" undef")

+" \t\t" ;

+(event.which?event.which:event.wich == 0?

0:" undef")

+ " \t\t"

+(event.charCode?event.charCode:event.charCode == 0?

0:" undef")< br $>
+" \t\t"

+(valid_one> = 32?String.fromCharCode(valid_one):

" Ctrl")

+" \t\t"

+ checkinput.value

+" \\\
" ;;

out.innerHTML + =消息;

}

函数check_press(e)

{

var event = e? e:window.event;

output_message(" keypress",event);

}

function check_up(e)

{

var event = e? e:window.event;

output_message(" keyup",event);

}

function check_down(e)

{

var event = e? e:window.event;

output_message(" keydown",event);

}

< / script>

< / head>


< body>

< h1>测试键盘事件< / h1>

< button onclick =" reset_all();">重置< /按钮>

< input id =" checkinput">< / input>

< pre id =" out"< / pre>

< / body>


< / html>


这是Firefox 2.0.0.14与Linux / Fedora的回报

keyup 0 undef 0 Ctrl

keyup 65 65 0 Aá

和Windows XP上的Firefox 2.0.0.14

keydown

keyup 0 undef 0 Ctrl

keyup 65 65 0Aá


I''m trying to find what character was pressed, using an accent with a
dead letter, e.g an á, on an input box.

I have made an small program to check the keyboard events keydown,
keypress and keyup, and only the
keyup one is fired two times. The first with a 0 keycode and the
characte code just later. No keydown or keypress events, and it is
not enough information to know what character was really pressed.
It happens with Firefox 2.0.0.14 on Linux. Firefox on Windows works
and behaves in a different way.

The input box is properly modified, so, I guess Firefox understands
whatever key sequence is
receiving from the Operating or the X system.

Any suggestion?

Thanks in advance.

解决方案

Joaquín Zuazo wrote on 18 mei 2008 in comp.lang.javascript:

I''m trying to find what character was pressed, using an accent with a
dead letter, e.g an *, on an input box.

I have made an small program to check the keyboard events keydown,
keypress and keyup, and only the
keyup one is fired two times. The first with a 0 keycode and the
characte code just later. No keydown or keypress events, and it is
not enough information to know what character was really pressed.
It happens with Firefox 2.0.0.14 on Linux. Firefox on Windows works
and behaves in a different way.

The input box is properly modified, so, I guess Firefox understands
whatever key sequence is
receiving from the Operating or the X system.

Any suggestion?

Why not compare the whole content on each keyup with the earlier content?

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


Thomas ''PointedEars'' Lahn wrote:

var charCode = (typeof e.charCode != "undefined"
? e.charCode
: (typeof e.keyCode != "undefined"
? e.keyCode
: charCode);

: charCode));


On 18 mayo, 11:52, Thomas ''PointedEars'' Lahn <PointedE...@web.de>
wrote:

Thomas ''PointedEars'' Lahn wrote:

var charCode = (typeof e.charCode != "undefined"
? e.charCode
: (typeof e.keyCode != "undefined"
? e.keyCode
: charCode);


: charCode));

This is the html test page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<!-- Keyboard events test program, by Joaquín Zuazo -->
<head>
<title>Testing keyboard events</title>
<meta http-equiv="encoding=UTF-8"></meta>

<script language="javascript" type="text/javascript">
window.onload=testkeys;
var checkinput, out;
var title = "Event\t\tkeyCode\t\twhich\t\tcharCode\tfromCharCo de
\tInput Box\n\n";

function testkeys()
{
checkinput = document.getElementById("checkinput");
out = document.getElementById("out");
out.innerHTML = title;
checkinput.onkeydown=check_down;
checkinput.onkeypress=check_press;
checkinput.onkeyup=check_up;
}
function reset_all()
{
out.innerHTML = title;
checkinput.value ="";

}
function output_message(function_name,event)
{
var valid_one = event.keyCode ? event.keyCode : event.which ?
event.which : event.charCode;
var message = function_name + "\t"
+ ( event.keyCode ? event.keyCode : event.keyCode == 0 ?
0 : "undef" )
+ "\t\t"
+ ( event.which ? event.which : event.wich == 0 ?
0 : "undef" )
+ "\t\t"
+ ( event.charCode ? event.charCode : event.charCode == 0 ?
0 :"undef" )
+ "\t\t"
+ ( valid_one >= 32 ? String.fromCharCode ( valid_one ) :
"Ctrl" )
+ "\t\t"
+ checkinput.value
+ "\n";
out.innerHTML += message;
}
function check_press(e)
{
var event = e ? e : window.event;
output_message("keypress",event);
}
function check_up(e)
{
var event = e ? e : window.event;
output_message("keyup ",event);
}
function check_down(e)
{
var event = e ? e : window.event;
output_message("keydown ",event);
}
</script>
</head>

<body>
<h1>Testing keyboard events</h1>
<button onclick="reset_all();">Reset </button>
<input id="checkinput"></input>
<pre id="out"</pre>
</body>

</html>

This is the return with Firefox 2.0.0.14 with Linux/Fedora
keyup 0 undef 0 Ctrl
keyup 65 65 0 A á
And with Firefox 2.0.0.14 on Windows Xp
keydown
keyup 0 undef 0 Ctrl
keyup 65 65 0 A á


这篇关于键盘事件和死信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆