473,322 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

trap keystrokes

Another fellow here must modify an application. On the web page, pressing
the enter key causes the form to submit. What users want is to remove enter
key functionality from within a textarea and cause the enter key to submit
the form, AND cause the F6 key to do what the enter key used to do inside
the text area. The idea I suggested is to trap keystrokes in the text area,
If the enter key is pressed, do the submit method. If F6 is pressed, disable
the enter key test then emulate an enter key by creating an event object.
The textarea should then insert a new line as if the enter key was pressed.
would that be the right approach and has anyone done something similar.
Thanks

--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
May 18 '06 #1
2 10071
The ENTER key functionality used by textarea is built into the browser
by default...I'm not sure you can trap this and use a different key
(JavaScript is much more limited than a desktop lanaguage like C++ or
Java). I would look at the "keypress" event of the textarea control,
and use window.event.KeyCode to check the keystrokes and see if you can
trap the ENTER key press and route it to another.

Larry

May 18 '06 #2
dr*****@yahoo.com wrote:
The ENTER key functionality used by textarea is built into the browser
by default...I'm not sure you can trap this and use a different key
(JavaScript is much more limited than a desktop lanaguage like C++ or
Java).
JavaScript, or ECMAScript implementations for that matter, was never
intended to be a "desktop language". And the features you describe are
not language features; they are features of the DOM (Document Object Model)
of the execution environment (here: browser) it runs in, which exposes
ECMAScript language binding for its interfaces to client-side scripting.
For example:
<URL:http://www.w3.org/TR/DOM-Level-2-Events/ecma-script-binding.html>
I would look at the "keypress" event of the textarea control,
True.
and use window.event.KeyCode to check the keystrokes and see if you can ^^^^^^^^^^^^^^^^^^^^ trap the ENTER key press and route it to another.


That assumes there is an object that can be referred to with window.event;
however, that is proprietary and restricted to IE only. It also assumes
that ECMAScript implementations are case-insensitive, which they are not.

A cross-browser (but due to the proprietary `event' value
not fully standards compliant) approach would be

function handleKeyPress(e)
{
if (!e) e = window.event;
if (e && e.keyCode == 13)
{
// handle Enter key
// return false; here to cancel the event
}
}

<textarea onkeypress="return handleKeyPress(event);">...</textarea>

However, users do not like it very much when you interfere with their
working environment without a very good reason for doing so:

<URL:http://codestyle.org/javascript/FAQ.shtml#suppressctrln>
PointedEars
--
Multiple exclamation marks are a sure sign of a diseased mind.
-- Terry Pratchett
May 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olli Piepponen | last post by:
Hi, I'm having a little problem catching keystrokes under Windows. I did a little research and found that with mscvrt.getch() one can cath a single key that is pressed. However this doesn't work...
3
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and...
5
by: Lucas Tam | last post by:
Hi all, Has anyone done this before? Send client side keystrokes to an application from a webpapge? This maybe more of a Javascript question. In short, I have an application on the client's...
2
by: zak | last post by:
I have some testing to do and I need to put a whole set of data in I want to Record and replay in a loop keystrokes. An idea
2
by: Tim Diggle | last post by:
I'm trying to enter data into a database application running under Citrix ICA Client. I'm doing it from a VBA macro running under Microsoft Excel 2000 (although it may need to be backwardly...
3
by: Gunnar Syren | last post by:
I'm trying to implement a macro feature in my application by recording and playing back keystrokes. At first I thought it would be enough to catch KeyDown in my main form, but I soon realized that...
1
by: zanthor | last post by:
Ok... so call me crazy, but I have an idea and I'm looking for where to start... I want to write an application that catches keystrokes and then either redirects them to the in focus window or...
1
by: John B. | last post by:
Please forgive my rant, but trapping keystrokes in .NET couldn't get much worse if someone tried. Sorry to vent my frustration but I've had no end of problems with this for the past 18 months. The...
3
by: Johnny | last post by:
Hi there, Does anyone know how I can trap F1 to activate help when a menu item is active, preferably without creating a "ToolStripMenuItem" derivative (so I can quickly wire this up using the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.