c4se記:さっちゃんですよ☆

.。oO(さっちゃんですよヾ(〃l _ l)ノ゙☆)

.。oO(此のblogは、主に音樂考察Programming に分類されますよ。ヾ(〃l _ l)ノ゙♬♪♡)

音樂は SoundCloud に公開中です。

考察は現在は主に Scrapbox で公表中です。

Programming は GitHub で開發中です。

event時の Key値の取得 - JavaScript

取り敢えず。
Mozilla のリファレンスからの引用です。(text/javascript を application/javascript へ変更。)


Altキーの取得。


<html>
<head>
<title>altKey example</title>

<script type="application/javascript">

function showChar(e){
alert(
"Key Pressed: " + String.fromCharCode(e.charCode) + "\n"
+ "charCode: " + e.charCode + "\n"
+ "ALT key pressed: " + e.altKey + "\n"
);
}

</script>
</head>

<body onkeypress="showChar(event);">
<p>
Press any character key,
with or without holding down the ALT key.<br/>
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>

true or false.


マウスボタンの取得。


<script type="application/javascript">

function whichButton(e)
{
// Handle different event models
var e = e || window.event;
var btnCode;

if ('object' == typeof e){
btnCode = e.button;

switch (btnCode){
case 0 : alert('Left button clicked');
break;
case 1 : alert('Middle button clicked');
break;
case 2 : alert('Right button clicked');
break;
default : alert('Unexpected code: ' + btnCode);
}
}
}

</script>

<p onclick="whichButton(event);">Click with mouse...</p>

  • 0 は普通の'クリック'であり、通常は左クリック
  • 1 は中ボタンであり、通常はホイールのクリック
  • 2 は右ボタンであり、通常は右クリック


メモメモ φ(・_・)



余計な事して、


alert*1;

とか。
動く保障↓。(tested on Mozilla Firefox 3 Beta 4)


var u = 2;
alert*2;

*1:function(){ switch(btnCode){ case 0:return 'Left button clicked'; case 1:return 'Middle button clicked'; case 2:return 'Right button clicked'; defalt:return 'Unexpected code: ' + btnCode; } })(

*2:function(){ switch(arguments[0]){ case 1:return 9; case 2:return 8; defalt:return 7; } return 6; })(u