This is the mail archive of the cygwin-xfree@cygwin.com mailing list for the Cygwin XFree86 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: numlock


From: "J S" <vervoom@hotmail.com>
Reply-To: cygwin-xfree@cygwin.com
To: cygwin-xfree@cygwin.com
Subject: Re: numlock
Date: Sun, 18 Apr 2004 09:36:37 +0000

[snip]


Thanks for your reply. Unfortunately our users' boxes are locked down (they're on XP) so they wouldn't be able to edit that file. I was really looking for a way to do this from the XFree startup script or configuration anyway.

OK. You asked for it. Below is a short C program which will check the state of the NumLock key and synthesize a keydown/keyup sequence of the NumLock key if it's down. Works on my box, which is Win2K, but I'm led to believe from the documentation that it should work with any 32-bit implementation of windows.


To build it, copy-paste the following source into a file (e.g. "numlockoff.c") then run gcc on it (e.g. "gcc -o numlockoff numlockoff.c"). Then add that to a convenient location on your client systems and add a call to it in your X startup script.

#include <stdio.h>
#define _WIN32_WINNT 0x0500
#include <windows.h>

int main()
{
   INPUT pInput[2];

   if (GetKeyState(VK_NUMLOCK) == 1)
   {
       pInput[0].type           = INPUT_KEYBOARD;
       pInput[0].ki.wVk         = VK_NUMLOCK;
       pInput[0].ki.wScan       = 0;
       pInput[0].ki.dwFlags     = 0; /* Nill for keydown */
       pInput[0].ki.time        = 0;
       pInput[0].ki.dwExtraInfo = 0;

       pInput[1].type           = INPUT_KEYBOARD;
       pInput[1].ki.wVk         = VK_NUMLOCK;
       pInput[1].ki.wScan       = 0;
       pInput[1].ki.dwFlags     = KEYEVENTF_KEYUP;
       pInput[1].ki.time        = 0;
       pInput[1].ki.dwExtraInfo = 0;

if (SendInput(2, pInput, sizeof(INPUT)) == 0)
{
fprintf(stderr, "Error: SendInput failed. NumLock was not turned off.\n");
}
}
}


_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now! http://toolbar.msn.com/go/onm00200415ave/direct/01/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]