From: David Mark on
I'd like some feedback on this. I'm more interested in the
functionality than code critiques at the moment (though either is
welcome).

Keyboard handling is one of the hardest cross-browser issues. I don't
claim this is perfect, but it smooths over various issues I've
encountered over the years when dealing with keyboard input. The most
important one for me is that auto-repeated arrow keys produce
consistent results. The way I dealt with this issue in the original
take was to optionally suppress the repeated keydown events and leave
it up to the application to use an interval (waiting for the matching
keyup to stop repeating). In this latest version I have removed that
burden.

I recently added some "real world" examples: a number spinner (without
extraneous buttons as it is only to test keyboard control) and a
character counter.

http://www.cinsoft.net/keyboard.html

Looks good to me at this point, having tested numerous browsers
released this century (and one released in the last). Of course, I
only have a US keyboard and at the moment cannot test on a Mac (and
have never been able to test on Unix of any sort). I know there are
lots of variations and can't imagine that my logic handles them all.
At this point I am open to observations and the inevitable
workarounds. But I'm sure as hell not using any browser sniffing. :)
From: Andrew Poulos on
On 26/07/2010 3:08 PM, David Mark wrote:
> I'd like some feedback on this. I'm more interested in the
> functionality than code critiques at the moment (though either is
> welcome).

Backspace:

Key down at test1: 8
Character at test1: "" (8)
Key up at test1: 8 duration: 127

Delete:

Key down at test1: 46
Key up at test1: 46 duration: 192

Insert:

Key down at test1: 45
Key up at test1: 45 duration: 120

For these (what I call) named keys I wonder if it would be a good idea
if a name was returned e.g. Backspace, Delete, Insert... Though I guess
that would stuff internationalisation.

---

PrtScr always only gives (no key down):

Key up at test1: 44 duration: undefined

---

Enter:

Character at test1: "
" (13)

Will it cause issues with it split over 2 lines?

Andrew Poulos
From: David Mark on
On Jul 26, 6:00 am, Andrew Poulos <ap_p...(a)hotmail.com> wrote:
> On 26/07/2010 3:08 PM, David Mark wrote:
>
> > I'd like some feedback on this.  I'm more interested in the
> > functionality than code critiques at the moment (though either is
> > welcome).
>
> Backspace:
>
> Key down at test1: 8
> Character at test1: " " (8)
> Key up at test1: 8 duration: 127
>
> Delete:
>
> Key down at test1: 46
> Key up at test1: 46 duration: 192
>
> Insert:
>
> Key down at test1: 45
> Key up at test1: 45 duration: 120

Looks good. What OS are you using?

>
> For these (what I call) named keys I wonder if it would be a good idea
> if a name was returned e.g. Backspace, Delete, Insert... Though I guess
> that would stuff internationalisation.

Yeah, that would be a rub.

>
> ---
>
> PrtScr always only gives (no key down):
>
> Key up at test1: 44 duration: undefined

I get nothing at all in Opera. The browser intercepts it apparently
(which is not unexpected for that key).

>
> ---
>
> Enter:
>
> Character at test1: "
> " (13)
>
> Will it cause issues with it split over 2 lines?

The logging is simply for debugging on the test page. The function
itself does not return such strings.

Thanks!
From: SAM on
Le 7/26/10 12:00 PM, Andrew Poulos a �crit :
> On 26/07/2010 3:08 PM, David Mark wrote:
>> I'd like some feedback on this. I'm more interested in the
>> functionality than code critiques at the moment (though either is
>> welcome).
>
> Backspace:
>
> Key down at test1: 8
> Character at test1: "" (8)
> Key up at test1: 8 duration: 127
>
> Delete:
>
> Key down at test1: 46
> Key up at test1: 46 duration: 192
>
> Insert:
>
> Key down at test1: 45
> Key up at test1: 45 duration: 120

On my Mac :

(that key is for 'Help')
Key up at test4: 45 duration: undefined


> For these (what I call) named keys I wonder if it would be a good idea
> if a name was returned e.g. Backspace, Delete, Insert... Though I guess
> that would stuff internationalisation.

and what about arrows keys ?

Key down at test4: 40
Key up at test4: 40 duration: 16
Key down at test4: 39
Key up at test4: 39 duration: 144
Key down at test4: 37
Key up at test4: 37 duration: 128
Key down at test4: 38
Key up at test4: 38 duration: 120

or page-up/down or document-up/down ?

Key down at test4: 36
Key up at test4: 36 duration: 136
Key down at test4: 35
Key up at test4: 35 duration: 143
Key down at test4: 33
Key up at test4: 33 duration: 135
Key down at test4: 34
Key up at test4: 34 duration: 120

> ---
>
> PrtScr always only gives (no key down):
>
> Key up at test1: 44 duration: undefined

No "PrtScr" on Mac --> I'ven't found that number 44

> ---
>
> Enter:
>
> Character at test1: "
> " (13)
>
> Will it cause issues with it split over 2 lines?
>
> Andrew Poulos

other "named keys" ...
Ctrl, Option, Apple :

Key down at test4: 17
Key up at test4: 17 duration: 176
Key down at test4: 18
Key up at test4: 18 duration: 112
Key down at test4: 224
Key up at test4: 224 duration: 104

Key [$*��] :

Key down at test4: 0
Character at test4: "$" (36)
Key up at test4: 0 duration: 152

Key [@�`]:

Key down at test4: 0
Key up at test4: 0 duration: 168

Key [@#] :

Key down at test4: 0
Character at test4: "@" (64)

Key down at test4: 16
Key down at test4: 0
Character at test4: "#" (35)
Key up at test4: 0 duration: 217
Key up at test4: 16 duration: 1680


--
sm
From: Nisse Engström on
On Sun, 25 Jul 2010 22:08:43 -0700 (PDT), David Mark wrote:

> I'd like some feedback on this. I'm more interested in the
> functionality than code critiques at the moment (though either is
> welcome).
>
> http://www.cinsoft.net/keyboard.html

Tested in Opera 10.54/Windows 98SE using an
IBM KB-9930 keyboard.

Letters and numbers
-------------------

Seem to work as expected, eg:

Key down at test4: 65
Character at test4: "a" (97)
Key up at test4: 65 duration: 104

Key down at test4: 16
Key down at test4: 65
Character at test4: "A" (65)
Key up at test4: 65 duration: 114
Key up at test4: 16 duration: 395

Key down at test4: 16
Key down at test4: 65
Character at test4: "A" (65)
Key up at test4: 65 duration: 112
Key down at test4: 66
Character at test4: "B" (66)
Key up at test4: 66 duration: 112
Key up at test4: 16 duration: 990

The Swedish letters (åäöÅÄÖ) are also fine.


Punctuation
-----------

Most single-key and shifted keys work fine (similar to the above).
There are some exceptions on the numerical keypad:

Key down at test4: 47
Character at test4: "/" (47)
Character at test4: "/" (47)
Key up at test4: 47 duration: 64

Key down at test4: 42
Character at test4: "*" (42)
Character at test4: "*" (42)
Key up at test4: 42 duration: 53

Key down at test4: 45
Key up at test4: 45 duration: 50

Key down at test4: 43
Character at test4: "+" (43)
Character at test4: "+" (43)
Key up at test4: 43 duration: 115

Also, when Num Lock is off, "7" is intercepted
by Opera and produces:

Key down at test4: 36
Key down at test4: 0

Most Alt-Gr combinations work fine, eg:

Key down at test4: 18
Key down at test4: 50
Shortcut character at test4: "2"
Character at test4: "@" (64)
Key up at test4: 50 duration: 113
Key up at test4: 18 duration: 271

Some observations:

Testing backslash ("+?\" key).

Key down at test4: 18
Key down at test4: 187
-> Shortcut character at test4: "»"
Character at test4: "\" (92)
Key up at test4: 187 duration: 97
Key up at test4: 18 duration: 325


Testing pipe ("<>|" key).

Key down at test4: 18
Key down at test4: 194
-> Shortcut character at test4: "â"
Character at test4: "|" (124)
Key up at test4: 194 duration: 107
Key up at test4: 18 duration: 325

Are those working as expected? Are the indicated
lines side effects of the characters not being
fully composed?


Composing keys
--------------

Composing keys work fine, except sometimes where
"AltGr" is involved. (See also Modifier keys below).

I saw the following happen a couple of times, but cannot
reproduce it anymore:

"^" (Shift-"¨^~"):

Key down at test4: 16
Key down at test4: 186
Key up at test4: 186 duration: 100
Key up at test4: 16 duration: 490
Key down at test4: 32
Character at test4: "^" (94)
Key up at test4: 32 duration: 50
-> Key down at test4: 18

followed by "~" (AltGr-"¨^~"):

Key down at test4: 186
Shortcut character at test4: "º"
Key up at test4: 186 duration: 86
-> Key up at test4: 18 duration: 47275
Key down at test4: 32
Character at test4: "~" (126)
Key up at test4: 32 duration: 120


Function keys:
--------------

Only keydown event (because of focus shift):

F1, F2, F3, F7, F8

Keydown and Keyup event:

F4, F6, F9, F10, F12

Nothing:

F5 (Reload)

And F11 resulted in:

Key down at test4: 122
Key down at test4: 376
Key up at test4: 122 duration: 11823
Key up at test4: 376 duration: 11750

Most or all function keys are also intercepted by Opera.


Special keys:
-------------

Windows key: Only works once per page load.

Key down at test4: 219

Menu key:

Key down at test4: 0

or

Key down at test4: 0
Key up at test4: 0 duration: 5209

Escape: Only works once per page load.

Key down at test4: 27

Shift-Escape: (also intercepted by Opera)

Key down at test4: 16
Key down at test4: 27
Key up at test4: 27 duration: 104
Key up at test4: 16 duration: 487

Tab:

Key down at test4: 9

And then Shift-Tab:

Key up at test4: 9 duration: 53
Key up at test4: 16 duration: 425

Caps Lock/Pause: Work fine.

Print Screen: Nothing.

Scroll Lock:

Key down at test4: 145
Character at test4: "‘" (145)
Key up at test4: 145 duration: 57

Num Lock:

Key down at test4: 144
Character at test4: "" (144)
Key down at test4: 376
Key up at test4: 376 duration: 106
Key up at test4: 144 duration: 111

Ins/Home/End/Page Up/Page Down: Keyup and Keydown.

Del:

Key down at test4: 46
Key down at test4: 376
Key up at test4: 46 duration: 117
Key up at test4: 376 duration: 66

Backspace:

Key down at test4: 8
Character at test4: "" (8)
Key up at test4: 8 duration: 60

Enter:

Key down at test4: 13
Character at test4: "
" (13)
Key up at test4: 13 duration: 64

Arrow Left/Right/Up: Keyup and keydown.

Arrow Down:

Key down at test4: 40
Key down at test4: 376
Key up at test4: 40 duration: 68
Key up at test4: 376 duration: 67

Prev/Next keys (on either side of the "Arrow Up" key;
Few keyboards have them) are fully intercepted by Opera.




Modifiers keys:
---------------

AltGr key, first time after page load or clearing log:

Key down at test4: 17
Key down at test4: 18
Key up at test4: 18 duration: 107

AltGr key again:

Key down at test4: 18
Key up at test4: 18 duration: 72

Then Ctrl key:

Key up at test4: 17 duration: 3073

Ctrl key again:

Key down at test4: 17
Key up at test4: 17 duration: 50

AltGr again:

Key down at test4: 17
Key down at test4: 18
Key up at test4: 18 duration: 47


----------
Extra keys
----------

Extra keys (IBM Support/Standby/CD operation and similar)
also generate Keydown and Keyup events.


----
Misc
----

Cut/Copy/Paste: works fine and also generate key events.
Eg.:

Key down at test4: 17
Key down at test4: 86
Shortcut character at test4: "V"
Key up at test4: 86 duration: -2
Key up at test4: 17 duration: 1



What did I forget?


/Nisse
 |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: trying to do AJAX
Next: how to assign a id as a variable