Alessandro Lacava’s Blog

Google
 

May 16, 2006

Sysinternals

Filed under: Computer, Windows, Security — alessandrolacava @ 9:36 am

The Sysinternals web site provides you with advanced utilities, technical information, and source code related to Windows internals that you won’t find anywhere else. Mark Russinovich and Bryce Cogswell alone write and update everything. Click here to visit the web site.


May 12, 2006

Using Javascript to detect the key pressed

Filed under: Computer, JavaScript — alessandrolacava @ 2:23 pm

Often it is useful to intercept the key pressed within an element of an HTML form, like a textbox and so on. For this purpose you can use Javascript to extract the code of the key that was pressed. Here is a snippet of code you can use--of course adapting it to your needs.

JavaScript:
  1. function keyPressed(e)
  2. {
  3. var code;
  4. if(window.event) //IE
  5. {
  6. code = e.keyCode;
  7. }
  8. else //other browsers
  9. {
  10. code = e.which;
  11. }
  12. //check, for example, if the Enter key was pressed (code 13)
  13. if(code == 13)
  14. {
  15. //Enter key was pressed
  16. }
  17. else
  18. {
  19. //Another key was pressed
  20. }
  21. }

Note: keyCode is used by Internet Explorer while which is used by the other browsers.

Then, from within a form, you can call this function. For example
[...]

HTML:
  1. <input onkeypress="javascript:keyPressed(event);" type="text" />

[...]


Next Page »