- In Mozilla, the order of events for keystrokes are
- keydown event. At this point only modification keys are recorded.
- keypress event. At this point the main key is recorded.
- keyup event. At this point only modification keys are available.
- Element updated.
keyCodeattribute of printable keys in keydown and keyup event handlers should not be used.
Examples
- Notice the
keyCodeis G even though thecharCodeis g.
keydown :ALT keyCode[ (18)], charCode[(0)] keydown :ALT-SHIFT keyCode[ (16)], charCode[(0)] keydown :ALT-SHIFT keyCode[G(71)], charCode[(0)] keypress:ALT-SHIFT keyCode[(0)], charCode[G(71)] keyup :ALT-SHIFT keyCode[G(71)], charCode[(0)] keyup : keyCode[ (16)], charCode[(0)] keydown :CTRL keyCode[ (17)], charCode[(0)] keydown :CTRL-ALT keyCode[ (18)], charCode[(0)] keydown :CTRL-ALT keyCode[G(71)], charCode[(0)] keypress:CTRL-ALT keyCode[(0)], charCode[g(103)] keyup :CTRL-ALT keyCode[G(71)], charCode[(0)] keyup :ALT keyCode[ (17)], charCode[(0)]
- Typing apostophe (') (ASCII code 39) corresponds to DOM keycode 222. Javascript's
String.fromCharCodetranslates numeric codes to UTF-8 characters. In UTF-8, 222 corresponds to capital Thorn (Þ) which is a letter used in Old English and still used in Icelandic.
keydown : keyCode[Þ(222)], charCode[(0)] keypress: keyCode[(0)], charCode['(39)] keyup : keyCode[Þ(222)], charCode[(0)]
- Typing "one" results in
keydown : keyCode[O(79)], charCode[(0)] value[] keypress: keyCode[(0)], charCode[o(111)] value[] keydown : keyCode[N(78)], charCode[(0)] value[o] keypress: keyCode[(0)], charCode[n(110)] value[o] keyup : keyCode[O(79)], charCode[(0)] value[on] keyup : keyCode[N(78)], charCode[(0)] value[on] keydown : keyCode[E(69)], charCode[(0)] value[on] keypress: keyCode[(0)], charCode[e(101)] value[on] keyup : keyCode[E(69)], charCode[(0)] value[one]
Notice, the full value of the input field is available only on keyup.
<html> <head> <style> b { color: blue; } </style> <script type="text/javascript"> function msg(e, txt) { var mydiv = document.getElementById("result"); var modifier = []; [[e.ctrlKey,"CTRL"], [e.altKey, "ALT"], [e.metaKey, "META"], [e.shiftKey, "SHIFT"], [e.getModifierState("OS"), "OS"], [e.getModifierState("CapsLock"),"Caps"]].forEach( function (x) { if (x[0]) { modifier.push(x[1]); } } ); var txt = mydiv.innerHTML + "<br/>" + txt + ":<b>" + modifier.join("-") + "</b>" + " keyCode[<b>" + String.fromCharCode(e.keyCode) + "</b>(" + e.keyCode +")]," + " charCode[<b>" + String.fromCharCode(e.charCode) + "</b>(" + e.charCode+")]"; if (document.getElementById("includeValue").checked) { txt = txt + " value[" + document.getElementById("maininput").value + "]"; } mydiv.innerHTML = txt; } function clearResult(e) { document.getElementById("result").innerHTML = ""; document.getElementById("maininput").value = ""; } </script> </head> <body> <form> <input id="maininput" type="text" size="80" onkeyup= "msg(event, 'keyup ')" onkeydown= "msg(event, 'keydown ')" onkeypress="msg(event, 'keypress')"> </input> <input id="includeValue" type="checkbox">Include Value</input> <input type="button" value="Clear" onclick="clearResult(event)"/> <br/> <div id="result" style="font-family:monospace"> </div> </form> </body> </html>
Monday, November 19, 2012
Javascript Note 3
Wednesday, November 14, 2012
Javascript Note 2
argumentsspecial variable available in the scope of a function. It contains all the arguments passed to a function. For example,
function p() { ... } function q(x) { ... } p(1,2,3,4); // arguments.length = 4 q(1,2,3,4); // arguments.length = 4. // Ie, the first argument is not swallowed by x.
Function.prototype.call(t[, args]*). Calls the function passing alongargsin a content wherethisrefers tot.
Function.prototype.apply(t, arg). Same ascallexcept the argument is an array. Coming from R, I had thought this meant the function was applied to each element ofarg.
Array.prototype.map(f). Applies functionfto each element of the array, returning a new array.
Array.prototype.forEach(f). Applies functionfto each element of the array but returnsundefined. In other words, basically used only for side effects such as printing to screen, writing to filesystem, etc.
Be aware that
1 + "5"; // "15"
"1" + 5; // "15"
"5" & 20; // 0
"5" & 21; // 5
"1" & "a"; // 0 (Octal of ASCII "1" is 061)
"1" & "b"; // 0
var x = { 1:"b", "5":"e" };
x["1"] == x[1]; // TRUE
x[5] == x["5"]; // TRUE
Tuesday, November 13, 2012
Javascript Note 1
Things I learned while writing a Thai transcription script in Javascript.
- The "keys" of an array are the indices!
var myarray = [ "potatoes" "tomatoes" "celery" ]; var sample = []; for (var x in myarray) { sample.push(x); } // sample = [ 0 1 2 ] NOT [ "potatoes" "tomatoes" "celery" ]
- Primitives are passed by value and the references of Objects are passed by value.
thisin a method refers to the object from which the method was invoked. See JavaScript “this” keyword.
var m = function() { this.value = this.value +1; } var a = { "value":1, "m":m }; var b = { "value":100, "a":a }; a.m(); // a.value = 2 b.a.m(); // a.value = 3, b.value = 100 b.a.m.call(b); // b.value = 101
- Objects in Javascript are associative arrays. To create an object is to create an associative array. One way of doing this is through the use of functions.
function f() { var x = 1; this.y = 100; this.addup = function addup(v) { this.y = this.y + v; }; return this; } var func1 = f(); var func2 = f(); func1.addup(1); [ func1.y, func2.y ]; // [ 101, 101 ] func2 = new f(); func2.addup(5); [ func1.y, func2.y ]; // [ 101, 105 ] [ func1.x, func2.y ]; // [ NaN, undefined ]
The last line is strange (Mozilla). I personally think it's a bug. I was expectingundefined. See Which way is best for creating an object in javascript? is “var” necessary before variable of object?.
undefinedis not a keyword in Javascript. It is just another variable that generally is undefined. The safest way to test if variablexis undefined istypeof(x) == "undefined". Note
var a = "welcome"; var b = { "a":"apple", "k":"kite", "z":"zebra" }; b["b"] == null; // TRUE b["b"] == undefined; // TRUE b["b"] === null; // FALSE b["b"] === undefined; // TRUE
However starting in Javascript 1.8.5,undefinedis a global non-writable variable whose type isundefined. So
var undefined = "trickster"; // doesn't do anything undefined === undefined; // TRUE typeof(undefined) == "undefined"; // TRUE
Wednesday, May 23, 2012
Dietrich Fischer-Dieskau passes
I was reading about Hans Hotter and Lotte Lehmann on Wikipedia before I decided to look up the famous baritone Dietrich Fischer-Dieskau where upon I found out that he passed away just several days ago on May 18, 2012 in his sleep in southern Germany. I first heard him in Karl Richter's 1958 recording of Bach's St Matthew Passion which is one of my favorite recordings of the work. There he sang the bass arias. But I had not listened to him for quite some time until I became interested in Wagner's Ring in 2010. The clip above shows him singing Gunther in Solti's famous 1960s studio recording of the Ring. Sometimes I think singers can over think their characters and then the feeling becomes artificial; but here I feel Fischer-Dieskau really gave Gunther the depth he was meant to have.
My roommate in college loved his Schubert's Die schöne Müllerin song cycle recording with Gerald Moore. The jaunty song Das Wandern begins the song cycle with the line Wandering is the miller's joy and ends with the stanza
Oh, wandering, wandering, my joy,
Oh, wandering!
Oh, master and mistress,
Let me continue in peace,
And wander!
Thursday, May 17, 2012
Donna Summer passes
Donna Summer passes away at age 63. My favorite song of hers as a kid was She Works Hard For Her Money. But after college, I rediscovered music from the disco era from where her song "Last Dance" is best known. Above is a clip from her appearance on the Midnight Special show in 1978. The video doesn't have the outrageous clothing and dancing of that era (which I love btw; you can see her in the 1978 movie Thank God It's Friday performing at a disco). But I only knew her by her songs so it was nice to hear her speak.
Saturday, May 12, 2012
MET Götterdämmerung

Ok, so I tried to sell my ticket for May 12th performance but got no buyer. I decided to stay for Act 1. I thought Dalayman would be singing Brünnhilde but it turned out Deborah Voigt will be singing Brünnhilde. I had watched the HD Live performance earlier this year.
- The Norns (Maria Radner, Elizabeth Bishop, Heidi Melton). I enjoyed their singing especially Radner and Melton; big voices.
- Siegfried (Stephen Gould). Jay Hunter Morris sang this in the HD Live performance. I really liked Gould in Siegfried and I still like him here. He even did a pretty good imitation of Gunther in the abduction scene.
- Brünnhilde (Deborah Voigt). Her voice sounded much better today than on Monday. Today, she managed to keep the "granny" sound to a minimum, and her voice seemed bigger. Her voice doesn't have warmth so the love duet was somewhat meh. But she gave us a nice big high C at the end of the duet. It sounded far better than those hojotoho she gave us in Die Walküre.
The Waltraute scene is Voigt's launching pad. Here she is getting into her element; Voigt's voice shines for fury, fear, and despair. Her confrontation with Siegfried was very exciting. When she curses Wotan for her situation, it was very convincing; and that scream she delivered when Siegfried seizes her ring was absolutely delicious. Unfortunately Act 1 ends and I had to leave. I wish I could have stayed because in the HD Live performance Voigt was even more impressive in Act 2.
I have not heard Dalayman in Götterdämmerung but I'm not sure she could do better than Voigt here. Though Voigt's voice is not as stable as Dalayman's, I feel Voigt is more expressive.
- Hagen (Hans-Peter König). Big voice and reliable as usual.
- Gunther (Iain Paterson). I didn't think much of his acting in the HD Live performance. But in the opera house his body language was surprisingly good.
- Gutrune (Wendy Bryn Harmer). Her singing is convincing.
- Waltraute (Karen Cargill). Waltraud Meier sang this in the HD Live performance. Not sure if the choreography changed but it seems better this time around; perhaps because there were no closeups shots to disorient me. I thought she sang very well.
John Keenan was the conductor. The opera started at 11am. I think it might have been too early for some of the brass players. There were more odd sounds coming from there than I heard before. I also thought some of the section were slow; should have picked up the tempo a little.
As in Das Rheingold, the Machine was better in house than on the theatre screen. The colors were all more vivid. Also I complained about the gloominess of the cliff scene in the theatre but it is nicely brighter in the opera house. The Gibichung wood pattern on the skirt looked pretty good too. When the magic fire flare to yellow in the abduction scene, I don't recall noticing in the theatre. The purple patterns shown during orchestral breaks are more complicated than I remember and I actually thought they were blue not purple in the theatre. But they used the same purple pattern twice. Couldn't they change the colors or patterns for each orchestral break?
So I said I vowed never to see Siegfried or Götterdämmerung again until a worthy Brünnhilde comes along. I take my words back. I will correct myself and restrict my vow to Siegfried because Brünnhilde is the big payoff in that opera. All in all, I wish I had watched the whole thing because it started off pretty well.
(Image from 101Thing's blog entry on Open Salon. However I believe Siegfried in that image is Morris not Gould)
Friday, May 11, 2012
MET Siegfried
I attended the performance of Siegfried on May 9th. Unfortunately I arrived late and had to watch Act 1 on a TV in Liszt Hall. Although I had a decent recollection of the dialogue, it would have been nice to have subtitles. The speaker sound was terribly 1-dimensional; I wondered if it was in mono. I had previously watched the HD Live performance in the autumn of 2011.
The conductor was Derrick Inouye. I felt the performance Inouye conjured up from the orchestra was the best that I've heard these three nights.
The scenery in Act 1 was just beautiful. The projection of water onto the skirt of the stage was pretty cool. But starting in Act 2, the production value started to drop a bit. Fafner's dragon looked like a larger version of the snake in a can. In Act 3, the rotisserie fire is less than magical. When Siegfried releases Brünnhilde from her sleep, I expected some more special effects. I think here more than any place, something special should happen. But nothing changes; the sky is still almost pitch black yet the sun is supposed to be shining. They seriously need to lighten up the scenery here and in Götterdämmerung.
For me, the last 30 minutes of Siegfried should be the climax of our 4 hour journey: the sound of Brünnhilde's voice piercing the male dominated soundscape like the sun after a storm. It wouldn't be so bad if the Siegfrieds weren't so good. But Dalayman and Voigt's Brünnhilde stand in stark contrast to Morris and Gould's Siegfried: the men have clear tones and display control over the technical demands of their roles, while the females have persistent ugly wobbles and struggle with the technical demands. I refrain from thinking about the magical Brünnhildes of Birgit Nilsson and Kirsten Flagstad because doing so would make me more angry. I vow never to attend another Siegfried or Götterdämmerung ever again until a Brünnhilde emerges who can sing the role at a level close to the men who sing Wotan and Siegfried.
- Siegfried (Stephen Gould). Jay Hunter Morris sang this in the HD Live performance. Morris has a brighter timbre but Gould's was still very pleasing. For such a difficult role, Gould made it sound easy.
- The Wanderer (Bryn Terfel). I have to give Terfel credit. He has sung so reliably in all three operas. He and Hans-Peter König were the pillars for this Ring Cycle.
- Mime (Robert Brubaker). Gerhard Siegel sang this in the HD Liver performance. I liked Brubaker in Das Rheingold and I liked him here. His big voice matches Siegfried's.
- Alberich (Richard Paul Fink). Eric Owens sang this in the HD Live performance. Fink does a good job but Owens has a darker timbre.
- Fafner (Hans-Peter König). I wished that during his fight scene with Siegfried that he would growl. Otherwise it's just seems plain silly with all that silence. It's a monster! It's supposed to growl while fighting.
- Woodbird (Erin Morley). She did a fine job though I wish she sounded sweeter.
- Erda (Patricia Bardon). Wagner is a bit cruel here with this role. Erda spends most of her time singing at the bottom of the clef including a bunch of B3, A3, and G3s. Then he forces her to sing a naked A♭-5. She managed to sing all these notes with respectable volume. In the theatre, her dress shimmered beautifully; however in the opera house, it was mostly dull and black with only occasional shimmer.
- Brünnhilde (Katarina Dalayman). Deborah Voigt sang this in the HD Live performance. Dalayman certainly has a bigger voice than Voigt. But those top notes do not come easily. And that constant giant wobble became tiresome after the first minute. However when the tempo quickened 1.5 minutes before the end, the wobble was reined in and suddenly the smog cleared. She opted for the C5 instead of the opera-ending money shot C6 but that's forgivable. Compared to Voigt's, Dalayman's performance was definitely better but still it was rather unsatisfying.
The conductor was Derrick Inouye. I felt the performance Inouye conjured up from the orchestra was the best that I've heard these three nights.
The scenery in Act 1 was just beautiful. The projection of water onto the skirt of the stage was pretty cool. But starting in Act 2, the production value started to drop a bit. Fafner's dragon looked like a larger version of the snake in a can. In Act 3, the rotisserie fire is less than magical. When Siegfried releases Brünnhilde from her sleep, I expected some more special effects. I think here more than any place, something special should happen. But nothing changes; the sky is still almost pitch black yet the sun is supposed to be shining. They seriously need to lighten up the scenery here and in Götterdämmerung.
For me, the last 30 minutes of Siegfried should be the climax of our 4 hour journey: the sound of Brünnhilde's voice piercing the male dominated soundscape like the sun after a storm. It wouldn't be so bad if the Siegfrieds weren't so good. But Dalayman and Voigt's Brünnhilde stand in stark contrast to Morris and Gould's Siegfried: the men have clear tones and display control over the technical demands of their roles, while the females have persistent ugly wobbles and struggle with the technical demands. I refrain from thinking about the magical Brünnhildes of Birgit Nilsson and Kirsten Flagstad because doing so would make me more angry. I vow never to attend another Siegfried or Götterdämmerung ever again until a Brünnhilde emerges who can sing the role at a level close to the men who sing Wotan and Siegfried.
Subscribe to:
Posts (Atom)