Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-02-2004, 02:44 PM   PM User | #1
kiransoanje
New Coder

 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
kiransoanje is an unknown quantity at this point
Question How can i raise ctrl keypress event on mouse click event

Hello Friends,
How can i call ctrl keypress event on mouse click event
kiransoanje is offline   Reply With Quote
Old 07-05-2004, 06:21 AM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Do you mean something like this?
Code:
document.onclick=function(e){
  if (!e) e=event;
  if (e.ctrlKey){
    alert("CTRL key is pressed.");
  }
  else if (e.shiftKey){
    alert("SHIFT key is pressed.");
  }
  else if (e.altKey){
    alert("ALT key is pressed.");
  }
}
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-05-2004, 07:44 AM   PM User | #3
kiransoanje
New Coder

 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
kiransoanje is an unknown quantity at this point
Actually i want to call CTRL key press event without pressing ctrl key..
i have following code..

<HTML>
<HEAD>
<script language="JavaScript">

function test(e)
{

//Here I want to call ctrl key press event without pressing ctrl key
var ctrlPressed = (window.Event) ? e.modifiers & Event.CTRL_MASK : e.ctrlKey;
alert(ctrlPressed);


}

</script>
</HEAD>
<BODY >
<form name=frmMain>
<input type=button value='Click Me' name='btnClick' onclick='test(event)'>
</form>
</BODY>
</HTML>


and i want to call ctrl event automatically without pressing ctrl key....

Last edited by kiransoanje; 07-05-2004 at 07:54 AM..
kiransoanje is offline   Reply With Quote
Old 07-05-2004, 08:10 AM   PM User | #4
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
I don't know what you exactly meant by "call ctrl key press event". Can you elaborate more? What's your ultimate reason for doing this?
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-05-2004, 10:47 AM   PM User | #5
kiransoanje
New Coder

 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
kiransoanje is an unknown quantity at this point
when i logout from my application,if at that moment if yahoo companion popup is enable i m not able to login again from the same browser. For login i have to use another browser. In this case if i press ctrl key, at the time of logout it does not give above problem. So i want to give functionality such that when i click on logout button, it will fire ctrlkey press automatically without pressing it manually event.

Problem does not occur if yahoo companion is disable.
kiransoanje is offline   Reply With Quote
Old 07-05-2004, 11:28 AM   PM User | #6
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Solve the root of the problem

What you need to solve is to find out why you can't login again from the same browser if that yahoo companion popup (what's that?) is enabled and find solution for it and not to find a solution for a "workaround".
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-05-2004, 12:42 PM   PM User | #7
kiransoanje
New Coder

 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
kiransoanje is an unknown quantity at this point
Though the root of cause is yahoo companion, i dont want to restrict user from utilization of yahoo companion. This is easily possible by pop up blocker or change in registry, but i think this is not the right solution.
kiransoanje is offline   Reply With Quote
Old 07-05-2004, 02:59 PM   PM User | #8
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
You can only capture not force a key press.....
Willy Duitt is offline   Reply With Quote
Old 07-22-2009, 03:49 AM   PM User | #9
vapeterson
New to the CF scene

 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vapeterson is an unknown quantity at this point
Smile Disabling a right-click for a PC AND ctrl-click for Mac

I've got a client on a Mac who wants right-click disabled so people don't easily take her images. Disabling a right-click for a PC is easy, but on a Mac it's not really a right-click (even if there's a 2-button mouse), it's a ctrl-click. After many hours of trial and error, I have finally got the code that will work in both platforms and on several browsers. I thought I'd share it.
(Yes, I understand that there really is no way to prevent an advanced web-user from downloading images and text, but the client really wants this to at least prevent some of the people)

I have included the code below:
This code goes between javascript tags in between the html head tags section

<!--

//Disable right mouse click Script
var message="Function Disabled!";

function clickIE4(){if (event.button==2){alert(message);return false;}}

function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){alert(message);return false;}}}

if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}
else if (document.all&&!document.getElementById){document.onmousedown=clickIE4;}
document.oncontextmenu=new Function("alert(message);return false")

//Disable ctrl key
if (document.all){
document.onkeydown = function (){
var key_ctrl = ctrlKey; // 17 is also ctrl Key

if (key_ctrl==event.keyCode){
alert(message);
return false;
}
}
}

// -->

Last edited by vapeterson; 07-22-2009 at 03:51 AM.. Reason: html script
vapeterson is offline   Reply With Quote
Old 07-22-2009, 07:43 AM   PM User | #10
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
vapeterson - why are you reviving this ancient thread?

I expect your code is fine in IE4 or NS4. But times have moved on.

Code:
<script type = "text/javascript">

document.onkeydown = function(ev) {	
var key;
ev = ev || event;
key = ev.keyCode;
alert ("Keycode = " + key);

if (key == 17) {
alert ("You pressed the CONTROL key");
return false;
}

}
</script>
As you say, there is no way of preventing users from copying your images or text, as they have already been downloaded and are in the browser cache. A waste of time to try, in fact. Also, users (advanced or not) can simply disable Javascript. See the FAQs.

And users will really love you if you disable the control key when they want to use
CTRL+C (Copy)
CTRL+X (Cut)
CTRL+V (Paste)
CTRL+Z (Undo)
and so on.

Suggest you forget the whole idea.

Last edited by Philip M; 07-22-2009 at 08:45 AM..
Philip M is offline   Reply With Quote
Old 07-22-2009, 04:20 PM   PM User | #11
fside
Regular Coder

 
Join Date: Mar 2008
Posts: 301
Thanks: 2
Thanked 30 Times in 30 Posts
fside is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
As you say, there is no way of preventing users from copying your images or text, as they have already been downloaded and are in the browser cache. A waste of time to try, in fact. Also, users (advanced or not) can simply disable Javascript.
Unless the script is what gets the text or images. I don't like the idea much. But some site owners are very jealous of their content.

Check out the way Rhapsody.com protects its lyrics. It's pretty effective. Annoying - but effective.
fside is offline   Reply With Quote
Old 07-22-2009, 11:05 PM   PM User | #12
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
on FF/windows at least, you can drag an image from a page to the desktop...
it's a little better to show the image as a css background property, rather than a tag.

That way, most browsers won't even offer "Save Image As..." on right-click, javascript or no javascript.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 07-23-2009, 07:20 PM   PM User | #13
Trinithis
Regular Coder

 
Join Date: Jun 2007
Location: USA
Posts: 527
Thanks: 26
Thanked 74 Times in 72 Posts
Trinithis will become famous soon enough
Print screen never fails.
Trinithis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:56 PM.


Advertisement
Log in to turn off these ads.