FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour TMsgBar KEYBOARD clause
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
TMsgBar KEYBOARD clause
Posted: Mon Feb 06, 2006 10:15 AM
When KEYBOARD clause is used we can click with the mouse on the Num, Caps and Ins items to toggle their status. But, specifically for Num and Caps, the status change is not reflected by the keyboard light and this brings to an inconsistency between the status itself and what the keyboard lights say.

Possible fixes are:

1) remove the item click at least on Num and Caps (but I would remove it on Ins also).

2) use the appropriate API to correctly change the lights status.

For the point 2, the following sample is from Francesco Saverio Giudice:

#include "common.ch"

PROCEDURE MAIN()

   ? "Attiva capslock"
   SetCapsLock( TRUE )

   Inkey( 0 )

   ? "Attiva numlock"
   SetNumLock( TRUE )

   Inkey( 0 )

   ? "Stato CAPSLOCK : " + IIF( GetCapsLock(), "ON ", "OFF" )
   ? "Stato NUMLOCK  : " + IIF( GetNumLock(), "ON ", "OFF" )

   Inkey( 0 )

   ? "Disattiva capslock"
   SetCapsLock( FALSE )

   Inkey( 0 )

   ? "Disattiva numlock"
   SetNumLock( FALSE )

   Inkey( 0 )

   ? "Stato CAPSLOCK : " + IIF( GetCapsLock(), "ON ", "OFF" )
   ? "Stato NUMLOCK  : " + IIF( GetNumLock(), "ON ", "OFF" )

   Inkey( 0 )

RETURN


#pragma BEGINDUMP

#include <windows.h>

#include "hbapi.h"

#define TOGGLED 0x0001

void SetKeyLock( BYTE vKey, BOOL bState )
{
   BOOL bCurrentState;

   bCurrentState = ( GetKeyState( vKey ) & TOGGLED );

   if( (bState && !bCurrentState) ||
       (!bState && bCurrentState) )
   {
      // Simulate a key press
      keybd_event( vKey,
                   0,
                   KEYEVENTF_EXTENDEDKEY | 0,
                   0 );

      // Simulate a key release
      keybd_event( vKey,
                   0,
                   KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                   0);
   }
}

BOOL GetKeyLock( int vKey )
{
   return ( GetKeyState( vKey ) & TOGGLED );
}

HB_FUNC( SETCAPSLOCK )
{
   SetKeyLock( VK_CAPITAL, hb_parl( 1 ) );
}

HB_FUNC( SETNUMLOCK )
{
   SetKeyLock( VK_NUMLOCK, hb_parl( 1 ) );
}

HB_FUNC( GETCAPSLOCK )
{
   hb_retl( GetKeyLock( VK_CAPITAL ) );
}

HB_FUNC( GETNUMLOCK )
{
   hb_retl( GetKeyLock( VK_NUMLOCK ) );
}

#pragma ENDDUMP


EMG

Continue the discussion