WEBアプリでファンクションキーを使う

<script type="text/javascript">
<!--
function estop(e) {
	// Mozilla(Firefox, NN) and Opera 
	if (e != null) {
		// イベントの上位伝播を防止 
		e.preventDefault(); 
		e.stopPropagation(); 
	// Internet Explorer 
	} else {
		// イベントの上位伝播を防止 
		event.returnValue = false; 
		event.cancelBubble = true; 
		event.keyCode = 0;
	}
	return true;
}

document.onkeydown = function(e) {
	var shift, ctrl; 

	// Mozilla(Firefox, NN) and Opera 
	if (e != null) {
		keycode = e.which;
		tagname = e.target.tagName.toUpperCase();
		ctrl    = typeof e.modifiers == 'undefined' ? e.ctrlKey : e.modifiers & Event.CONTROL_MASK; 
		shift   = typeof e.modifiers == 'undefined' ? e.shiftKey : e.modifiers & Event.SHIFT_MASK; 

	// Internet Explorer 
	} else { 
		keycode = event.keyCode; 
		tagname = window.event.srcElement.tagName.toUpperCase();
		ctrl    = event.ctrlKey; 
		shift   = event.shiftKey; 
	} 

	switch(keycode){
	case 27 :
		if ( tagname == "TEXTAREA" ) {
			alert('Escキーをキャンセルしました');
			estop(e);
		}
		break;
	case 112 : //F1
		location.href = "http://yahoo.co.jp/";
		estop(e);
		break;
	case 113 : //F2
		location.href = "http://www.google.co.jp/webhp?complete=1&hl=ja";
		estop(e);
		break;
	case 116 : //F5
		location.href = "http://www.excite.co.jp/";
		estop(e);
		break;
	case 121 : //F12
		location.href = "http://www.excite.co.jp/";
		estop(e);
		break;
	default :
		//デバック用
		//alert(keycode + 'が押されました');
		return true;
	}
	return false;
}

//-->
</script>
The following two tabs change content below.
しゃちょー

しゃちょー

有限会社こだまシステム社長。18歳の時からIT業界で働く。趣味はモータースポーツ。マイブームはダイエット。

関連記事

[メモ]CentOS5.6のPHPをソース版に入れ替える

CentOS5.6にデフォルトでインストールされるPHPではなく、必要最低限(?)のモジュールのみでコンパイルしたPHPに入れ替える必要があったので、その手順をメモ。

プリウス以上のエコカー

ちょっと画像で遊んでみました…

Solarisで1970年1月1日からの日数を表示するコマンド

GNU版のdateとかだと、+%sで1970年1月1日0時0分0秒からの秒数(エポック)を表示できるが、Solarisの純粋な環境だとこれが出来ない。そこで、無理やりこんな1行コマンドを作ってみました。

PHPでcsvを2次元配列に読み込む

<?php $file_name = “data.csv”; $fp = fopen( $file_na […]

ベクトルの内積による相関係数の算出

CSVから$data[列][行]という2次元配列にいれたデータについて、1列目とその他の列とで相関係数を算出する。