Loading ...
Sorry, an error occurred while loading the content.
 

GetKeyState()

Expand Messages
  • rafelafrance
    I m not sure if this is the appropriate forum for these kinds of things (vs a developer forum). But... I had a need to get the state of the caps & num lock
    Message 1 of 1 , Aug 30, 2005
      I'm not sure if this is the appropriate forum for these kinds of
      things (vs a developer forum). But...

      I had a need to get the state of the caps & num lock keys for
      testing. The IsKeyPressed() function is using the GetAsyncKeyState()
      function and returning a boolean. After some fiddling with the XS
      module I realized this wasn't going to get me what I needed. So I
      added a new function to *.XS (with corresponding *.PM tag) to get the
      key state directly. It's a hack, only slightly modifying the code
      that was already there:

      int
      KeyState(name)
      char* name;
      CODE:
      int vkey;
      int found;
      int len = strlen(name);
      if (len >= 3)
      name[3]=NUL;
      found = findvkey(name, &vkey);
      if (found) {
      OutputDebugString("Trying key\n");
      RETVAL = GetKeyState(vkey);
      } else if (strlen(name)==1 && (isdigit(*name) || isalpha(*name)))
      {
      OutputDebugString("Trying alphanum\n");
      RETVAL = GetKeyState(toupper(*name));
      }else {
      OutputDebugString("No key\n");
      RETVAL = 0;
      }
      OUTPUT:
      RETVAL

      The both routines could be refactored and made more robust but its a
      start.



      PS: Standard disclaimers: I'm new to XS & Windows programming etc.
      etc.

      PPS: I've made other XS file changes like the GetClientRect was not
      implemented (?) & I have a function to get a pixel's color from the
      screen (a very specific need). More are sure to follow.
    Your message has been successfully submitted and would be delivered to recipients shortly.