detecting a keystroke?

Everything having to do with programming, all languages (VB, C/C++, C#, HTML, JAVA, PHP, etc)


detecting a keystroke?

Postby HUGO » Wed Apr 02, 2008 7:34 am

so considering i know nothing about programming, could this be done in vbscript?
would it be like pages of typing or is it simple
bad credit loan re mortgage uk Permanent PR0-PR7 One Way Link Building Service Mortgage Introducers
Posts: 6
Joined: Tue Nov 27, 2007 11:38 am

Postby Mirey86 » Wed May 14, 2008 6:30 am

You could do it, you would just have to use the WSH in order to load the VBScript. But then you would want it to run in the background which would require a timer that would recycle and detect a keystroke, then take the appropriate action(s).

mirey 8)
Posts: 5
Joined: Wed May 14, 2008 6:27 am

Re: detecting a keystroke?

Postby Daeva » Thu Jul 10, 2008 9:36 am

Not sure what you are using this for, but it can be accomplished in many different languages.
I have some javascript code I wrote a while ago that does this. Hope it helps.
Code: Select all
<?xml version="1.0" charset="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" dir="ltr" lang="en-us" xml:lang="en-us">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1;" />
  <title>Test form elements</title>
  <script type="text/javascript">
   //David Kyle 4/5/07
   function nextElement(obj, e, ind) {
   var replaceText = new String("");

   document.getElementById("outputSpan").innerHTML = "You are in " + + ": " + e.keyCode + "Index number " + getIndex(obj); // used for debugging
    if (navigator.appName == "Opera" && navigator.appVersion >= "9") {
     if (e.keyCode == 78 || e.keyCode == 46) {
     replaceText = obj.text;
     obj.text = replaceText.replace("."," ");
     } else {
     } // end else
    } else {
     if (e.keyCode == 110 || e.keyCode == 190) { //the . symbol has 2 different ways of being pressed on standard keyboards.
      replaceText = obj.value;
      obj.value = replaceText.replace("\.","");
      document.forms[0].elements[getIndex(obj)+1].focus(); // set focus to next element
     } // end if
    } // end if
   } // end function nextElement

   function getIndex(input) { // get index searches your form for a match
   /* NOTE
     Javascript's API doesn't provide a method(that is supported accross multiple platforms) to return the index of the element we are talking about.  So this method takes a brute force approach to finding the element's index, which we will use to skip to the next element.
    var index = new Number(0);
    for(index = 0; index < document.forms[0].length; index++) { // while we still have form elements
     if (document.forms[0].elements[index] == input) {
      return index;
     } // end if
    } // end for loop

   } // end function getIndex
  <form id="form1" name="form1" method="POST" action="">
   <div id="mainDiv">
    <table id="mainTable" name="mainTable">
        <td colspan="2" valign="bottom" align="center" style="text-align: center;">
         Testing auto-tab form elements
        <td colspan="1" valign="top" align="left">
         <label for="field1">Fields</label>
        <td colspan="1" valign="top" align="left">
         <input id="field1" name="field1" type="text" style="width: 30px;" maxlength="3" onkeyup="nextElement(this, event);" />
         <input id="field2" name="field2" type="text" style="width: 30px;" maxlength="3" onkeyup="nextElement(this, event);" />
         <input id="field3" name="field3" type="text" style="width: 30px;" maxlength="3" onkeyup="nextElement(this, event);" />
         <input id="field4" name="field4" type="text" style="width: 30px;" maxlength="3"/>
        <td colspan="2" valign="top" align="left">
         <span id="outputSpan"></span>

What i was using it for, was input for a program where you had to put ip addresses in. It would detect when you press the "." key to forward you to the next field as if you were 10-keying in an ip address. Opera has a different key mapping than IE and FF, so keep that in mind. You basically just have to play with it to find they keycode for the key you are looking for.
Posts: 18
Joined: Fri Feb 16, 2007 3:35 pm
Location: Streetsboro, Ohio

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest