fikiwan Posted January 13, 2013 Share Posted January 13, 2013 hello I make a hotkey for aplication Webpleas Chek my code... <!DOCTYPE html><html><head><meta http-equiv="X-UA-Compatible" content="IE=Edge" ><style type="text/css">body{background:green;} #over{ background: rgba(0,0,0,0.8); width: 100%; height: 100%; top: 0; bottom: 0;left: 0;right: 0; border: 0px solid blue; position: fixed; } #data{border:3px solid white; width: 300px; margin:100px auto;background: white; color:blue; font:2em 'Agency FB';text-align: center;} a{cursor: pointer;}</style><script type="text/javascript">window.onload = dokeyHot(); var KeyHot = []; function dokeyHot () { if (window.event) { document.captureEvents(event.KEYPRESS); } document.onkeydown = function(e){ var charCode = (e.which) ? e.which : e.keyCode; KeyHot[charCode] = true; if (KeyHot[27]) { // ESC Button document.getElementById("box").innerHTML = ""; } } } function tekan () { var dawal = "<div id='over'>"; var dakhir = "</div>"; var data = "<div id='data'>Pleas Turn Button ESC</div>" document.getElementById("box").innerHTML=dawal+data+dakhir; }</script></head><body><div id="box"></div><button onclick="tekan();">Tekan</button></body><html> if press button tekan will display a dialogbox and if press ESC in keyboard dialogbox will lost but that just run very well just for first time.. if I press again tekan dialogbox will lost with all button in keyboard ... ??? I want dialogbox lost just if press button ESC keyboard.. thnks for correct Link to comment Share on other sites More sharing options...
jeffman Posted January 13, 2013 Share Posted January 13, 2013 KeyHot is a global variable. If you set the value of KeyHot[27] to true, it STAYS true until your script changes it. But you gain nothing by using an array in this case. if (charCode == 27) is the only test you should need. 1 Link to comment Share on other sites More sharing options...
fikiwan Posted January 14, 2013 Author Share Posted January 14, 2013 KeyHot is a global variable. If you set the value of KeyHot[27] to true, it STAYS true until your script changes it. But you gain nothing by using an array in this case. if (charCode == 27) is the only test you should need.Thank for the help correct Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now