1. When are the keyboard events fired?
a) When the user manually calls the button
b) When the user clicks a key
c) When the user calls the modifier
d) When the user right clicks the mouse
Explanation: The keydown and keyup are the keyboard events are fired when the user presses or releases a key on the keyboard. They are generated for modifier keys, function keys, and alphanumeric keys.
2. How does a user generate multiple keydown events?
a) Repeating the same process
b) Pressing multiple keys
c) Pressing the key longer than usual
d) Pressing the key multiple times
Explanation: If the user holds the key down long enough for it to begin repeating, there will be multiple keydown events before the keyup event arrives. Pressing the key for long time results in multiple calls to the function onkeypress.
3. Which property is used to specify the key type when pressed?
Explanation: The keyCode property returns the Unicode character code of the key that triggered the onkeypress event, or the Unicode key code of the key that triggered the onkeydown or onkeyup event. The event object associated with these events has a numeric keyCode property that specifies which key was pressed.
4. For what value does the keyCode property persists even when a Shift key is pressed for adding punctuation character.
a) Special characters
Explanation: The number keys always generate keyCode values for the digit that appears on the key, even if you are holding down Shift in order to type a punctuation character.
5. Which of the following are not key event properties?
a) Code key
b) Alt Key
c) Ctrl Key
d) Shift Key
Explanation: altKey, ctrlKeY, shiftKey, and metaKey are key event object’s properties, which are set to true if the corresponding modifier key is held down when the event occurs. The keyCode values of ShiftKey, ctrlKey, altKey are respectively 16, 17 and 18.
6. Which of the following key property holds the key name as a string?
Explanation: The DOM Level 3 Events defines a new key property that contains the key name as a string. Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object.
7. Which of the following is not the value the key property will hold if the key is a function key?
Explanation: If the key is a function key, the key property will be a value like “F2”, ”F8” or ”F9”etc. The Keys from F1-F12 are known as function keys.
8. Which method is used to add a binding?
Explanation: The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
9. Which method is used to remove a binding?
c) remove(Bind b)
Explanation: The unbind() method removes event handlers from selected elements. This method can remove all or selected event handlers, or stop specified functions from running when the event occurs.
10. Which of the following are the parameters passed to the keymap after installation?
a) Key property
b) Key name
c) Keydown event’s object
d) Key stroke
Explanation: After the keymap is installed, the following parameters are passed:
- The event object for the keydown event.
- The key identifier of the key that was pressed.
Identifier key contains the information of the key that is pressed and the object information about the function to be performed when the key is pressed.