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業界で働く。趣味はモータースポーツ。マイブームはダイエット。

関連記事

CentOS7からiptablesがfirewalldに変わったよ

先日どハマリしてしまったCentOS7のポートの解放について、語ります。

Mastodonで出来ること、出来ないこと。

Mastodonのインスタンスを立ち上げて色々と試してみたので、情報共有します!

ターミナルの任意の位置にechoする

シェルスクリプトを書いていると、「毎回20行目にフッタを表示させたい」なんてことがたまにあります。

【Linuxで画像加工】RAW形式のファイルから順次ダーク減算して比較明合成をする方法(メモレベルの覚書)

  for file in IMG_*.CR2 do dcraw -w -j -W -4 $file […]

ウイルスにご注意ください

年末から年始にかけて、コンピュータウイルスGumblar(ガンブラー)の被害が急速に拡大しています。
このウイルスの感染力はかなり強いと感じています。