![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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? |
#3
| |||
| |||
|
|
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? |
#4
| |||
| |||
|
|
var charCode = (typeof e.charCode != "undefined" ? e.charCode : (typeof e.keyCode != "undefined" ? e.keyCode : charCode); |
#5
| ||||||||||
| ||||||||||
|
|
On 18 mayo, 11:52, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) 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: |
|
checkinput.onkeydown=check_down; checkinput.onkeypress=check_press; checkinput.onkeyup=check_up; |
|
var valid_one = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; |
|
+ "\t\t" + ( event.which ? event.which : event.wich == 0 ? 0 : "undef" ) |
|
+ "\t\t" + ( valid_one >= 32 ? String.fromCharCode ( valid_one ) : "Ctrl" ) |
|
[..] out.innerHTML += message; |
|
function check_press(e) { var event = e ? e : window.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 á |
#6
| |||
| |||
|
|
Joaquín Zuazo wrote: On 18 mayo, 11:52, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) 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: Why have you not just used my code or the reliable test site I pointed you to instead of this, sorry, mostly clueless nonsense? checkinput.onkeydown=check_down; checkinput.onkeypress=check_press; checkinput.onkeyup=check_up; Avoid those proprietary features, use event handler attributes or DOM 2 Event methods when possible. var valid_one = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; I had chosen the order of evaluation with purpose. Mozilla and MSHTML support `keyCode' but implement it differently; only Mozilla and Safari support charCode which is equivalent to MSHTML's keyCode *on keypress*. If you reverse evaluation order like this, you get misleading results. Especially, String.fromCharCode(event.keyCode) is not supposed to return the character that would have been/has been input in all cases. + "\t\t" + ( event.which ? event.which : event.wich == 0 ? 0 : "undef" ) Here is also a typo. + "\t\t" + ( valid_one >= 32 ? String.fromCharCode ( valid_one ) : "Ctrl" ) See above. [..] out.innerHTML += message; There is no need for proprietary error-prone `innerHTML' here. function check_press(e) { var event = e ? e : window.event; See my code for a more efficient and reliable feature test. /script /head body h1>Testing keyboard events</h1 button onclick="reset_all();">Reset </button The `button' element should not be used when the `input' element with type `button' suffices. input id="checkinput"></input The end tag for the `input' element is forbidden in HTML, per the Specification's normative prose. 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 á I don't see `keypress' which my followup was all about. Are you saying `keypress' never occurs there? (I can confirm the opposite for Fx 2.0.0.14 on Windows XP.) Double-check with fixed test script code, Valid markup and the `keypress' attribute, or with the test case I pointed you to. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee |
#7
| |||
| |||
|
|
[103 quoted lines] Yes no keypress events. Only two keyup events as shown. |
#8
| |||
| |||
|
|
Joaquín Zuazo wrote: [103 quoted lines] Yes no keypress events. Only two keyup events as shown. (sic!) http://jibbering.com/faq/#FAQ2_3 PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee |
|
? e.charCode : (typeof e.keyCode != "undefined" ? e.keyCode : charCode); :charCode); |
#9
| |||
| |||
|
|
On 19 mayo, 01:25, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de wrote: JoaquÃ*n Zuazo wrote: [103 quoted lines] Yes no keypress events. Only two keyup events as shown. (sic!) [...] |
|
There is another place to check keyboard events: http://unixpapa.com/js/testkey.html that I have worked before. The result is the same. Also there is a line I don't understand from your code Is it a typo? var charCode = (typeof e.charCode != "undefined" ? e.charCode : (typeof e.keyCode != "undefined" ? e.keyCode : charCode); :charCode); |
|
var charCode = charCode if no other value is available ? |
#10
| |||
| |||
|
|
Thomas 'PointedEars' Lahn wrote: JoaquÃ*n Zuazo wrote: [103 quoted lines] Yes no keypress events. Only two keyup events as shown. (sic!) There is another place to check keyboard events: http://unixpapa.com/js/testkey.html that I have worked before. The result is the same. |
|
keydown keyCode=68 (D) which=68 (D) charCode=0 keyIdentifier=undefined keypress keyCode=0 which=100 (d) charCode=100 (d) keyIdentifier=undefined keyup keyCode=68 (D) which=68 (D) charCode=0 keyIdentifier=undefined |
![]() |
| Thread Tools | |
| Display Modes | |
| |