Forum Moderators: open

Message Too Old, No Replies

Capturing F-Keys and Shift-F-Key in JS

         

txbakers

4:06 pm on Jul 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




I have a nice script that can capture the pressing of F-Keys 1 - 12 based on the keycode in JavaScript.

I also need to capture when a user presses the ShiftKey WITH an F-Key. This allows for up to 24 F-Keys with mainframe applications.

I found the information for the window.event routine to capture when I press the ShiftKey, but still haven't found the right combination to capture when a key is pressed and held.

Does anyone know that bit of code?

Thanks.

tedster

1:25 pm on Jul 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I poked around quite a bit looking for an answer, but you've definitely asked one of the toughest questions of the year.

All I've learned is that there is a way to tell when there is a keyup event while another key is still held, which sounds like a hopeful direction. But the keycode particulars, etc. weren't to be found.

So, this is really a "bump", not an answer.

BlobFisk

1:58 pm on Jul 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably tried this, but detecting both Shift and an F-key together doesn't work, does it? In pseudocode:


if(F-key && Shift Key) {
then do something;
}

Or is the event capture lost on the shift key after the initial press?

txbakers

5:02 pm on Jul 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Blob, but you're supposition is right, once a key is pressed the event is lost, so we couldn't check for both. I know Windows has a mechanism for tracking the length of holding a key - when I amble and hold the shift key down too long I get the message "Do you want to start the accessibility features." so I know it exists.

Just can't find it. I've seen it action, but couldn't get to the script to "learn" how it was done.

ricfink

2:14 pm on Jul 11, 2003 (gmt 0)

10+ Year Member



I would imagine that using the onkeydown event along with the onkeyup event would enable you to see if the shiftkey was pressed and still not released and set a global variable accordingly - and the value of that variable can be referenced when another onkeydown event fires.

That's the way I'd proceed.

Maybe I'll whip together a test page later today.

DrDoc

2:15 am on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a nice script that can capture the pressing of F-Keys 1 - 12 based on the keycode in JavaScript.

I'd be interested in seeing that :)

txbakers

2:40 am on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's at my office now. I'll post it on Monday. It's very small.

DrDoc

5:06 am on Jul 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks! Looking forward to seeing it

ricfink

3:00 pm on Jul 12, 2003 (gmt 0)

10+ Year Member



IE offers the shiftKey property of the event object which returns true if the shift key is/was depressed when the event fires.

Put the checkeydown() sample function below in a script tag and add the onkeydown event to the body tag as below. When you hold down shift and press F4, the alert will pop up showing the function has fired.

Note: For keys like F4 (115) which are functional within IE (F4 drops down the addressbar), make sure you've got the event.returnValue = false statement included like the example.

function checkeydown() {
if (event.shiftKey && event.keyCode == 115) {
event.returnValue = false;
alert('Shift + F4 Pressed')
}
}
<body onkeydown="checkeydown();">

txbaker wrote:
"Thanks Blob, but you're supposition is right, once a key is pressed the event is lost, so we couldn't check for both."

This is only half-right. yes the event only fires once. But the event is a javascript object and objects can have properties and shiftKey is a property of the event object.
It answers the question: what was the state of the shift key when that event fired?