Does anyone have any sample code to turn on
and off the NumLock key?
All help appreciated...gord
----------------------------------------------
go...@ipoline.com
I'm pretty sure I've seen code to do that posted here
previously. Maybe you could find it by searching AltaVista?
-------------------------------------------------------------
Cindy Ross cin...@rtp.vnet.ibm.com
(These opinions are just mine, I only represent myself, etc.)
-------------------------------------------------------------
Only a week ago I posted a copy of someone's post from last year. This
really is becoming a tedious FAQ....
Here it is yet again:
Article: 35307 of comp.os.os2.programmer.misc
From: ner...@central.co.nz (Neil Daniell)
Newsgroups: comp.os.os2.programmer.misc
Subject: Re: NumLock Programming
Date: 25 Mar 1996 11:23:40 GMT
Organization: Internet Company of New Zealand
Lines: 131
Message-ID: <4j5vns$2...@status.gen.nz>
References: <4i7al0$13...@rtpnews.raleigh.ibm.com> <4i7al0$13...@rtpnews.raleigh.
Reply-To: ner...@central.co.nz
NNTP-Posting-Host: neridan.central.co.nz
X-Newsreader: NeoLogic News for OS/2 [version: 4.5 YO Beta]
In message <4iugr9$1f...@rtpnews.raleigh.ibm.com> -
rsch...@vnet.ibm.com(richard schneiderman)22 Mar 1996 15:26:33 GMT writes:
:>
:>I am looking for a way to program the num lock button on my keyboard. I saw
that
:>there is a DosDevIOCtl function and category to perform this, but don't know
how
:>to set up the parameters. Can someone please help me.
:>
:>Thank you in advance.
:>
:>LONG LIVE OS/2
:>
:>Richard Schneiderman
:>rsch...@vnet.ibm.com
:>
Setting / Unsetting NumLock Status in OS/2 App
==============================================
[1] Required variables:
HFILE hfile; // File handle for device
ULONG ulAction;
ULONG ulLength;
BYTE KeyState[257];
SHIFTSTATE strShiftState;
unsigned short usLightState;
[2] Open keyboard device for use with DosDevIOCtl:
DosOpen (
"KBD$",
&hfile,
&ulAction,
0L,
0,
FILE_OPEN,
OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
0 );
[3] Obtain Shift Status information
using DosDevIOCtl Category IOCTL_KEYBBOARD ( 0x0004 )
Function KBD_GETSHIFTSTATE ( 0x0073 )
ulAction = 0;
ulLength = sizeof ( strShiftState );
DosDevIOCtl (
hfile,
IOCTL_KEYBOARD,
KBD_GETSHIFTSTATE,
0,
0,
&ulAction,
&strShiftState,
sizeof( strShiftState ),
&ulLength );
[4] Get Keyboard state table:
WinSetKeyboardStateTable (
HWND_DEKSTOP,
&KeyState[1],
FALSE );
[5] Set shift and key state:
If setting key ON:
KeyState[VK_NUMLOCK+1] |= 0x01;
strShiftState.fsState |= NUMLOCK_ON;
If setting key OFF:
KeyState[VK_NUMLOCK+1] &= ~0x01;
strShiftState.fsState &= ~NUMLOCK_ON;
[6] Update keyboard state table:
WinSetKeyboardStateTable (
HWND_DEKSTOP,
&KeyState[1],
TRUE );
[7] Update shift state:
using DosDevIOCtl Category IOCTL_KEYBBOARD ( 0x0004 )
Function KBD_SETSHIFTSTATE ( 0x0053 )
ulAction = sizeof ( strShiftState );
ulLength = 0;
DosDevIOCtl (
hfile,
IOCTL_KEYBOARD,
KBD_SETSHIFTSTATE,
&strShiftState,
sizeof( strShiftState ),
&ulAction,
0,
0,
&ulLength );
[8] Set LED status
using DosDevIOCtl
Category IOCTL_KEYBBOARD ( 0x0004 )
Function KBD_ALTERKEYBOARDLED ( 0x005A )
NB: This constant is NOT predefined,
will require specific declaration.
usLightState = ( strShifState.fsState & ( CAPSLOCK_ON | NUMLOCK_ON |
SCROLLLOCK_ON ) ) >> 4;
ulAction = sizeof ( usLightState );
DosDevIOCtl (
hfile,
IOCTL_KEYBOARD,
KBD_ALTERKEYBOARDLED,
&usLightState,
sizeof( usLightState ),
&ulAction,
0,
0,
&ulLength );
[9] Close device:
DosClose ( hfile );
---
* PDQWK 2.5 #1
Here it is, as picked off this very newsgroup:
===== From: wil...@ingres.com
WinSetKeyboardStateTable (HWND_DESKTOP, abKeyState, FALSE);
abKeyState[VK_NUMLOCK] |= 1;
WinSetKeyboardStateTable (HWND_DESKTOP, abKeyState, TRUE);
===== rha...@dialnet.net
#define INCL_WININPUT
#define INCL_DOSPROCESS
#include <OS2.H>
#include <stdio.h>
void main()
{
BOOL rc;
BYTE KeyState[256]; /* This is a 256 byte table */
/* indexed by virtual key */
/* value. */
/* For any virtual key, the */
/* 0x80 bit is set if the key */
/* is down, and zero if it is */
/* up. The 0x01 bit is set */
/* if the key is toggled, */
/* (pressed an odd number */
/* of times), otherwise it is */
/* zero. */
DosSetPriority( PRTYS_PROCESS, PRTYC_IDLETIME, 2,0);
while(1)
{
rc=WinSetKeyboardStateTable(HWND_DESKTOP,
/* the address of the second element is passed so that the */
/* key number corresponds to the array index */
&KeyState,
FALSE); /* get a copy of the keyboard */
/* state. */
if(rc==FALSE)
{
WinAlarm(HWND_DESKTOP, WA_ERROR);
return;
}
KeyState[VK_NUMLOCK] |= 0x01; /* set the NUMLOCK key to */
/* on state */
rc=WinSetKeyboardStateTable(HWND_DESKTOP,
&KeyState,
TRUE); /* set a copy of the keyboard */
/* state. */
DosSleep(5000);
if(rc==FALSE)
puts("Error Setting copy");
} // While
} // main
I will add this code to the next issue of EDM/2, so that we can just
point people at that instead of having to post it all the time. Is there
anyone out there willing to maintain a c.o.o.p.misc FAQ?
Excellent idea.