Im very new to programming and im trying to make a code which will cause an image to only appear if the ctrl key is not being pressed.
<script language=JavaScript>
document.onkeydown = checkKey;
var Showimg = False;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '17') {
alert('test');
Showimg = True;
}
}
</script>
This is the code ive currently got. I have code in another division below which has the code for the image in.
I'm very new to CSS and javascript, and basically most coding in general, so im not sure if its possible to get an image to no longer show if the ctrl key is pressed, as "if" statements dont seem to work outside the script, but the image code wont work inside the script.
This may not be detailed enough, sorry.
FalseandTruetofalseandtrue.language="javascript">.ctrlkey to be in addition to it? If you are looking to only act on keypresses where the key is held down, you could check out thectrlKeyproperty on theKeyboardEvent. developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/ctrlKey Great place to start.languageis deprecated, andtypeis optional. You can just use<script>.