منتديات ترياق العرب

منتديات .بطاقات.اذكار المسلم .صور.تصميم مواقع.مكتبة اسلاميه.برامج.ولدينا الكثير ان شاء الله
 
الرئيسيةمكتبة الصورس .و .جبحـثالتسجيلالأعضاءالمجموعاتدخول

شاطر | 
 

 نبذة عن لغة الجافا

استعرض الموضوع السابق استعرض الموضوع التالي اذهب الى الأسفل 
كاتب الموضوعرسالة
KILLER
المدير العام
المدير  العام


ذكر عدد الرسائل : 40
نقاط : 0
تاريخ التسجيل : 21/04/2008

مُساهمةموضوع: نبذة عن لغة الجافا   الأربعاء مايو 28, 2008 12:53 pm

Keyboard/ Mouse event handlers


Event HandlerDescription
onkeypressFires when the user presses a key on the associated element (ie: document, DIV etc). A combination of onkeydown and onkeyup.
onkeydownFires when the user depresses a key (but not yet released) on the associated element.
onkeyupFires when the user releases a key after having depressed it on the associated element.
onclickFires when the user clicks on an element. A combination of onmousedown and onmouseup.
onmousedownFIres when the user holds the mouse down over an element.
onmouseupFires when the user releases the mouse after having hold it down over the element.
ondblclickFires when the user double clicks the mouse over an element.
Keyboard Event object properties


Below lists the relevant properties within the Event Object that cater to keyboard actions. Recall that in IE, the event object is accessed directly via window.event, while in Firefox and other browsers, it is indirectly passed as the first parameter the callback function associated with this event.
PropertiesDescription
altKey, ctrlKey, shiftKeyBoolean properties that indicate whether the Alt, Ctrl, or Shift keys were pressed at time of the event.
charCodeReturns the character code of the key pressed during an onkeypress event. and is only set for keys in which a character is associated with it (ie: "a", "b", or "z"). Keys with no character association like "Shift" or "Ctrl" do not qualify. Other points:

  • Different values are returned for upper and lowercase characters (ie: "a" versus "A").
  • To convert the Unicode value returned to the actual character, use String.fromCharCode(returned_charCode).
  • This property is NOT set during onkeydown and onkeyup events. For these two events, the keyCode property below is set instead.
  • This property is NOT available in IE, and always returns "undefined". In IE, only the keyCode property is supported.

Example:

document.onkeypress=function(e){
var e=window.event || e
alert("CharCode value: "+e.charCode)
alert("Character: "+String.fromCharCode(e.charCode))
}
isCharBoolean property that indicates if the key pressed has a character associated with it. If the user pressed "F1" for example, the property returns false. Buggy as of Firefox 2.x, not supported in most other browsers (ie: IE, Opera 9 etc).
keyCodeProperty indicating the key code pressed during an onkeydown and onkeyup event, and in IE, onkeypress as well. The keyCode property is set whenever a key is pressed, including non character keys like "Shift" or "Ctrl".

  • IE only supports the keyCode property and NOT the charCode property. It is set during all three keyboard events in that browser- onkeypress, onkeyup, and onkeydown.
  • keyCode is only set during the onkeypress event in Firefox and other browsers, while for onkeydown and onkeyup, the charCode property is set instead. The two are always mutually exclusive.
  • To convert the key code value returned to the actual character pressed, use String.fromCharCode(returned_keyCode).
  • Despite the fact that Firefox doesn't set the keyCode property during the onkeypress event, e.which (see below) is always set, which you can use on all three keyboard event handlers.

Be careful when accessing the keyCode property during an onkeydown or onkeyup event, as it is set whenever any key is pressed, including non character keys like "Shift". This means if you try to press "Shift+a" to try and get the keyCode for "A", you will always end up getting two keyCodes instead, one for "Shift" and one for "A" in that order. What you won't get regardless is the keyCode for "a", as keyCode always returns the unicode value of the uppercase version of a character. To derive the keyCode for "a" (lowercase), you must probe the keyCode returned during the onkeypress event in IE, and since Firefox doesn't set keyCode during onkeypress, switch to e.charCode or e.which instead for that browser. Sounds confusing? Yes it is. Check out the below two examples for a more hands on explanation:
Compare this example (try pressing "a" or "Shift a" in the "char" field):


Char: Keycode:




var charfield=document.getElementById("char")
charfield.onkeydown=function(e){
var e=window.event || e
document.getElementById("keycode").value=e.keyCode
}



Char: Keycode:


var charfield=document.getElementById("char")
charfield.onkeydown=function(e){
var e=window.event || e
document.getElementById("keycode").value=e.keyCode
}



to this example (try pressing "a" or "Shift a" in the "char" field):


Char: Keycode:




var charfield=document.getElementById("char")
charfield.onkeypress=function(e){
var e=window.event || e
var keyunicode=e.charCode || e.keyCode
document.getElementById("unicode").value=keyunicode
}



Char: Keycode:


var charfieldalt=document.getElementById("charalt")
charfieldalt.onkeypress=function(e){
var e=window.event || e
var keyunicode=e.charCode || e.keyCode
document.getElementById("unicode").value=keyunicode
}


metaKeyBoolean property indicating whether the META key was pressed. NOT supported in IE.
returnValueSet to false to cancel any default action for the event.
whichReturns the unicode value of the key pressed whether it has a character associated with it or not. Behaves similar to IE's version of the keyCode property and supported in Firefox/ Opera. NOT supported in IE.
The below table lists the Unicode character code value of the primary keys on your keyboard:



var keychars=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
var numchars=[0,1,2,3,4,5,6,7,8,9]
var fchars=['F1:112','F2:113','F3:114','F4:115','F5:116','F6:117','F7:118','F8:119','F9:120','F10:121','F11:122','F12:123']
var miscchars=['Space:32','BackSpace:8','Enter:13','Shift:16','Ctrl:17','Alt:18']

function alphanumericchart(arr, start, limit){
document.write('
    \n')
    for (var i=start; i



    document.getElementById("alphanumeric").onkeypress=function(e){
    var e=window.event || e
    var keyunicode=e.charCode || e.keyCode
    //Allow alphanumeric keys, plus BACKSPACE and SPACE
    return (keyunicode>=65 && keyunicode
الرجوع الى أعلى الصفحة اذهب الى الأسفل
معاينة صفحة البيانات الشخصي للعضو
 
نبذة عن لغة الجافا
استعرض الموضوع السابق استعرض الموضوع التالي الرجوع الى أعلى الصفحة 
صفحة 1 من اصل 1

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
منتديات ترياق العرب :: ..:.منتديات التكنلوجيا والانتر نت.:.. :: :::منتدى لغات البرمجة:::-
انتقل الى: