473,513 Members | 2,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Testing for shift or ctrl within a click event.

Right now I have code like this which works in IE (this fires on an
onclick):

function f_Click(x)
{

if (window.event.shiftKey)
{

I'd like to find the simplest way to make this work cross-browser. In
another post I found:

document.onkeydown = function (e) {
evt = e || event;
if (evt.shiftKey) alert('shift');
}

But
1) I haven't figured out how to return the result into a variable.
2) I notice that once this code executes, it will execute again just by
hitting the shift button, without clicking.

Thanks

Jul 23 '05 #1
2 3051
jhco...@yahoo.com wrote:
Right now I have code like this which works in IE (this fires on an
onclick):

function f_Click(x)
{

if (window.event.shiftKey)
{

I'd like to find the simplest way to make this work cross-browser. In another post I found:

document.onkeydown = function (e) {
evt = e || event;
if (evt.shiftKey) alert('shift');
}

But
1) I haven't figured out how to return the result into a variable.
2) I notice that once this code executes, it will execute again just by hitting the shift button, without clicking.

Thanks


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title>untitled</title>
<script type="text/javascript">

document.onclick = function(e)
{
e = e || window.event;
if (e.shiftKey)
{
d = document;;
d.getElementById('r').appendChild(d.createTextNode ('!'));
}
}

</script>
</head>
<body>
<span id="r" style="font:64px arial;"></span>
</body>
</html>

Jul 23 '05 #2
Thanks, but I have the possibility of clicking in other part of the
page (this is a tree control), and enabling an event handler here
doesn't work for me, since whatever it does may happen when I click
something else.

I also tried putting the handler somewhere else, but it executes after
my f_click function, so it doesn't work for me.

The IE code seems to simply be a property. I would like something that
simple, but my next thought is to write something using onkeypress and
onkeyup to set a variable indicating if one of these keys is down.
Thanks,
Jim

Jul 23 '05 #3

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

Similar topics

7
15470
by: Paul Cooper | last post by:
Dear All, I am working on a piece of Javascript code that needs to detect a mouse-click, shift-click and control-click. The code is not my own - it is a part of a much larger suite of routines. The code as it stands does not work in Firefox, and I suspect that the task of feature detection (which currently depends on browser detection) can...
10
27789
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? Tim
3
14125
by: ngreplies | last post by:
I have a need for an extra facility to be available when the user presses the SHIFT key whilst clicking on either a Button Control or a textbox. I am using both VB6 and VB.NET2002. Could anyone please advise on the best way of managing this. Thanks in advance Terry
3
5482
by: surya52 | last post by:
I want to disable right click in my application.Here are my requirements. 1. I don't what to turn off shift click for the page. I want to turn it off for specific links. 2. I want shift-click to be replaced with a regular click. Meaning, when the user shift-clicks the link they will be taken to the "HREF" within the current browser window and...
7
7185
by: Csaba Gabor | last post by:
I'd like to detect the shift key when a button is "clicked" in Firefox/Mozilla. If the button is clicked with the mouse, no problem. However, if the onclick event is keyboard originated, then my method is not working. Same thing for SELECT elements. The simple web page below shows the issue. Click with the mouse while holding down the...
2
1821
by: Eadwine Rose | last post by:
I have this little bitty script on my site that makes a jump to the top of the screen when one double left clicks anywhere in the page. I was wondering if it could be altered so the double left click stays present as it is, and when a key is pressed alongside it, say.. shift, ctrl, alt.. , it will jump to the bottom instead of the top. ...
7
4924
by: yonatnl | last post by:
why In every time I pressing Ctrl + Shift + B, Visual Studio Compiles The solution? I Did not changed a thing in the Code. It was Ok 2 days a Go... and After getting Latest Version from the source safe The .. it compile everything each Time I press Ctrl Shift B
4
3935
by: t3projects | last post by:
I'm working on controlling a windows media player I'm trying to figure out how to control it with keys like CTRL+SHIFT+P to play it. The problem is that I don't know how to capture all three at the same time. I'm ONLY supporting IE because that's what the client only want's supported. I have been reading through the forums but nothing about...
0
2190
by: Yusuf Incekara | last post by:
I 've assigned a shortcut key for CTRL+SHIFT+1 key in my application. I can handle these keys in Form's keydown event. private void Form1_Load(object sender, EventArgs e) { this.KeyPreview = true; } private void Form1_KeyDown(object sender, KeyEventArgs e) { label1.Text = e.Control.ToString() + "|" + e.Shift.ToString() + "|" +...
0
7565
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...
1
7128
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
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...

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.