TMsgBar KEYBOARD clause

TMsgBar KEYBOARD clause

Postby Enrico Maria Giordano » 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:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 41 guests