Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NumLock Programming

5 views
Skip to first unread message

richard schneiderman

unread,
Mar 13, 1996, 3:00:00 AM3/13/96
to
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

richard schneiderman

unread,
Mar 22, 1996, 3:00:00 AM3/22/96
to

Martin Lafaix

unread,
Mar 22, 1996, 3:00:00 AM3/22/96
to
In article <4iugr9$1f...@rtpnews.raleigh.ibm.com>,

rsch...@vnet.ibm.com(richard schneiderman) wrote:
>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.

Using DosDevIOCtl functions is not sufficient if you use PM: you also
need to call WinSetKeyboardStateTable.

#define INCL_DOSFILEMGR
#define INCL_DOSDEVICES
#define INCL_DOSDEVIOCTL
#define INCL_WININPUT

#include <os2.h>
#include <stdio.h>

VOID SetNumLockState(BOOL bSet) /* if bSet is true, enable NUMLOCK */
{
SHIFTSTATE ss;
BYTE KeyState[257];
BOOL bSet;
APIRET rc;
ULONG ulAction, ulLength;
HFILE hf;

rc = DosOpen("KBD$",
&hf,
&ulAction,
0L,
0,
FILE_OPEN,
OPEN_ACCESS_READONLY|OPEN_SHARE_DENYNONE,
0);

/* reading keyboard state */
ulAction = 0;
ulLength = sizeof(ss);
rc = DosDevIOCtl(hf,
IOCTL_KEYBOARD,
KBD_GETSHIFTSTATE,
0,
0,
&ulAction,
&ss,
sizeof(ss),
&ulLength);

WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, FALSE);

/* changing state -- if bSet is true, enables NUMLOCK */
if(bSet)
{
KeyState[VK_NUMLOCK] |= 0x01;
ss.fsState |= NUMLOCK_ON;
}
else
{
KeyState[VK_NUMLOCK] &= ~0x01;
ss.fsState &= ~NUMLOCK_ON;
}

/* seting keyboard state */
WinSetKeyboardStateTable(HWND_DESKTOP, KeyState, TRUE);

ulAction = sizeof(ss);
ulLength = 0;
rc = DosDevIOCtl(hf,
IOCTL_KEYBOARD,
KBD_SETSHIFTSTATE,
&ss,
sizeof(ss),
&ulAction,
0,
0,
&ulLength);

rc = DosClose(hf);
}

Hope this helps


Martin
--
laf...@alto.unice.fr
Team OS/2
<a href="http://wwwi3s.unice.fr/~lafaix/os2.html">OS/2 en français!</a>

Neil Daniell

unread,
Mar 25, 1996, 3:00:00 AM3/25/96
to
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 );

0 new messages