473,785 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting up hotkeys using onKeyPress

Is it possible to set up hotkeys using onkeypress? I know it can be
done with the usual alphanumeric keys, but what about function keys?
or using ctrl/alt combinations? Does anybody have a tutorial/guide?
Jul 23 '05 #1
2 11128
Hasan Ammar wrote on 18 aug 2004 in comp.lang.javas cript:
Is it possible to set up hotkeys using onkeypress? I know it can be
done with the usual alphanumeric keys, but what about function keys?
or using ctrl/alt combinations? Does anybody have a tutorial/guide?


I use this code with onkeydown(!!!), also for F5/6/7/8.

[IE only, because the page is for my personal administrator use only]
[The alert()s are leftovers from the debugging fase]

onkeydown='druk ()'

.....

function druk(){
x=event.keyCode
//alert(x)
if((x==8)||(x== 32)){ // bs or space
doenv(ouderbnum )}
else if (x==27){ // esc
location.reload ()}
else if (x==37){ // li
doenv(tvorig)}
else if (x==39){ // re
doenv(tvolgend) }
else if (x==40){ // dn
doenv(svorig)}
else if (x==38){ // up
doenv(svolgend) }
else if (x==36){ // back numb
doenv(bnumdef)}
else if (x==35){ // help
helpen()}
else if (x==45){ // toggle test
text()}
else if (x==116){ // F5
doen(onder[0])}
else if (x==117){ // F6
doen(onder[1])}
else if (x==118){ // F7
doen(onder[2])}
else if (x==119){ // F8
doen(onder[3])}
//else {alert(x)}
}

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2
am****@gmail.co m (Hasan Ammar) wrote in message news:<e9******* *************** ****@posting.go ogle.com>...
Is it possible to set up hotkeys using onkeypress? I know it can be
done with the usual alphanumeric keys, but what about function keys?
or using ctrl/alt combinations?

PointedEars provied this link to a post titled "Re: mouseless
navigation" the link is:
<http://www.w3.org/TR/html4/interact/forms.html#adef-accesskey>

I copied the following from the article:

In this example, we assign an access key to a link defined by the A
element. Typing this access key takes the user to another document, in
this case, a table of contents.

<P><A accesskey="C"
rel="contents"
href="http://someplace.com/specification/contents.html">
Table of Contents</A>

The invocation of access keys depends on the underlying system. For
instance, on machines running MS Windows, one generally has to press
the "alt" key in addition to the access key. On Apple systems, one
generally has to press the "cmd" key in addition to the access key.
I wrote up a Javascript program for detecting key presses too. It has
a Netscape path.

The function is written so it could be invoked by setting the
document.onkeyp ress global variable.

Looks like you can either set the event handler via the
statement below or in the onkeypress event handler of the
html body statement. If you use the statement below, IE
will not be passing the event variable to the function
processKey and you will have to preference window to
the event variables for the IE portion of the code.

document.onkeyp ress = processKey;
Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>onkeypre ss example</title>

<SCRIPT type="text/javascript">
function processKey(even t)
{
if (typeof event == "object" &&
typeof event.which == "number")
{
// Netscape style event
alert("Netscape : event.which = " + typeof event.which +
" " + event.which + " letter is " +
String.fromChar Code(event.whic h));

alert("event.sh iftKey = " + event.shiftKey +
" event.ctrlKey = " + event.ctrlKey +
" event.altKey = " + event.altKey +
" event.metaKey = " + event.metaKey);
//control-y goes to yahoo
if (event.which == 121 && event.ctrlKey == true)
{
location.replac e("http://www.yahoo.com") ;
return false;
}

}
else
{
// We assume IE
/* ***
// Doing an alert seems to confuse IE.
// The event will be changed after the alert.
alert("IE: window.event.ke yCode = " +
window.event.ke yCode +
" letter is " +
String.fromChar Code(window.eve nt.keyCode) +
"\n" +
" window.event.sh iftKey = " + window.event.sh iftKey +
" window.event.ct rlKey = " + window.event.ct rlKey +
" window.event.al tKey = " + window.event.al tKey +
"\n" +
" ... Warning: " +
"IE event handle is confused after this alert");
*** */
//control-y goes to yahoo
if (window.event.k eyCode == 25 )
{
location.replac e("http://www.yahoo.com") ;
window.event.re turnValue = false;
return;
}
}

return true;
}

</SCRIPT>
</head>
<body onkeypress='ret urn processKey(even t);'>
<p>Lets look for a key press.</p>
<form>
<input type=text size=20>
</form>
</body>
Jul 23 '05 #3

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

Similar topics

0
316
by: skumar | last post by:
I need to access the Tabpages by hotkeys "alt+P" in case of "Principals" as one of the Tabpage. Also i need to underline the word "P" in "Principals" so that user is informed about the hotkey.If i use "&" in front of the word "P",it is not underlining the word.It just stays "&" itself. I know we can add this hotkeys to toolbars,buttons and lots of other controls.
1
2309
by: Matthew Wells | last post by:
How do you prevent someone from using Ctrl+, (ctl + comma) or Ctl + . (Ctl + perios) to get to design view. I have all the normal properites turned off (Access special keys, F!!, etc) but nothing seems to stop that one. I tired using AutoKeys to remap it, but I keep getting "Invalid Syntax" or "Invalid keystroke combination". Most of these new hotkeys are really for developers and we should be able to stop end users from using them. I...
3
2859
by: Matthew Wells | last post by:
I'm reposting because an idiot replied without reading the whole message. I've tried autokeys and it isn't working for this combination. Please read on. While in form view, how do you prevent someone from using Ctrl+, (ctl + comma) or Ctl + . (Ctl +period) to get to design view. I have all the normal properites turned off (Access special keys, F11, etc) but nothing seems to stop that one. I tried using AutoKeys to remap it, but I...
2
4180
by: ~toki | last post by:
How can i take the control of the key events in Class2 ? This is the code snipped that i'd tried (after try some others): public class Main : System.Windows.Forms.Form { protected virtual void OnKeyPress(System.Object sender, System.Windows.Forms.KeyPressEventArgs e) { /* Do Nothing */ } } public class Class1 : Main
2
2098
by: Martin Hjärtmyr | last post by:
I have a program that uses Hotkeys! And they works just fine! I use this hotkeylib: http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows_Messages/Hot_Key_Form/HotKeyForm_zip_HotKeyForm_HotKeyForm_HotKeyFormLib_cs.asp But my hotkeys suddenly stops working when i use this: ShowInTaskbar = false;
8
2818
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);" TextBox2.Attributes.Add("onKeyPress", jscode) You will notice that jscode contains the JavaScript Logical And operator (&&). However, ASP.NET renders this as &amp;&amp; in the code that is
3
3743
by: Bernd Eichelsdorf | last post by:
Hi, I would like to add hotkeys to my webapp - it's running on a barcode scanner, that has got a number pad and the keys F1 - F4. I would like to add hotkeys, so that when the user presses F1, the focus is set on form field 1 and so on... Is that possible with javascript, if so, how?
1
7237
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip to the DB server -- is that correct? 2) On a user's click of a button, one of the actions in the button OnClick event is to set the selectedindex of the 2nd DDL to that of the 1st. I get a runtime error here that says that the given index is...
0
1266
by: Octavius Khan | last post by:
How can I set system hotkey that will only work for specific applications. For example, I have a system tray application that uses hotkeys to perform certain tasks like placing text into a memo field of another application, etc. However, I don't want these hotkeys to be for "every" application. I just want them to work for, let's say Notepad or Wordpad or Internet Explorer. I already know how to set systemwide hotkeys, but I'd like to...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.