...

View Full Version : How can i raise ctrl keypress event on mouse click event



kiransoanje
07-02-2004, 03:44 PM
Hello Friends,
How can i call ctrl keypress event on mouse click event

glenngv
07-05-2004, 07:21 AM
Do you mean something like this?


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.");
}
}

kiransoanje
07-05-2004, 08:44 AM
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....

glenngv
07-05-2004, 09:10 AM
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?

kiransoanje
07-05-2004, 11:47 AM
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.

glenngv
07-05-2004, 12:28 PM
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".

kiransoanje
07-05-2004, 01:42 PM
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.

Willy Duitt
07-05-2004, 03:59 PM
You can only capture not force a key press.....

vapeterson
07-22-2009, 04:49 AM
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. :D
(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;
}
}
}

// -->

Philip M
07-22-2009, 08:43 AM
vapeterson - why are you reviving this ancient thread?

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


<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.

fside
07-22-2009, 05:20 PM
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.

rnd me
07-23-2009, 12:05 AM
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.

Trinithis
07-23-2009, 08:20 PM
Print screen never fails.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum