KeyToggle() and Num, Caps and Ins keys

KeyToggle() and Num, Caps and Ins keys

Postby frose » Thu Feb 09, 2012 3:25 pm

Hi,

want to switch in insert mode with
- KeyToggle( VK_INSERT ) or
- Eval( oWnd:oMsgBar:oKeyIns:bAction ) or
- Mouse click in the message bar on 'Ins'
but it's not working :(

In addition the NUMLOCK- and CAPSLOCK-LED's on the keyboard don't react, if the Buttons 'Num' or 'Caps' are mouse clicked in the message bar :(

With the informations out of these two threads:
viewtopic.php?f=6&t=2551
viewtopic.php?f=3&t=1577

I changed the method 'KeybOn()' in msgbar.prg as follows:
- Replaced 'KeyToggle( VK_NUMLOCK )' with 'SetNumLock( !GetNumLock() )' in ::oKeyNum
- Replaced 'KeyToggle( VK_CAPITAL )' with 'SetCapsLock( !GetCapsLock() )' in ::oKeyCaps
- Added ', Set( _SET_INSERT, ! Set( _SET_INSERT ) )' in ::oKeyIns

Here is the complete method and the C functions:
Code: Select all  Expand view
METHOD KeybOn() CLASS TMsgBar

   if ::oKeyNum == nil
      // keep the ':=' below for XBase++ compatibility
      ::oKeyNum := TMsgItem():New( Self, "Num", ::GetWidth( "Num" ) + 12,,,, .t.,;
                                  { || SetNumLock( !GetNumLock() ), ::oKeyNum:Refresh() } )
      ::oKeyNum:lTimer = .t.
      ::oKeyNum:nClrDisabled = GetSysColor( COLOR_BTNSHADOW )
      ::oKeyNum:lActive = GetKeyToggle( VK_NUMLOCK )
      ::oKeyNum:bMsg  = { || ::oKeyNum:lActive := GetKeyToggle( VK_NUMLOCK ), "Num" }
   endif

   if ::oKeyCaps == nil
      // keep the ':=' below for XBase++ compatibility
      ::oKeyCaps := TMsgItem():New( Self, "Caps", ::GetWidth( "Caps" ) + 12,,,, .t.,;
                                  { || SetCapsLock( !GetCapsLock() ), ::oKeyCaps:Refresh() } )
      ::oKeyCaps:lTimer = .t.
      ::oKeyCaps:nClrDisabled = GetSysColor( COLOR_BTNSHADOW )
      ::oKeyCaps:lActive = GetKeyToggle( VK_CAPITAL )
      ::oKeyCaps:bMsg = { || ::oKeyCaps:lActive := GetKeyToggle( VK_CAPITAL ), "Caps" }
   endif

   if ::oKeyIns == nil
      // keep the ':=' below for XBase++ compatibility
      ::oKeyIns := TMsgItem():New( Self, "Ins", ::GetWidth( "Ins" ) + 12,,,, .t.,;
                                  { || KeyToggle( VK_INSERT ), Set( _SET_INSERT, ! Set( _SET_INSERT ) ), ::oKeyIns:Refresh() } )
      ::oKeyIns:lTimer = .t.
      ::oKeyIns:nClrDisabled = GetSysColor( COLOR_BTNSHADOW )
      ::oKeyIns:lActive = GetKeyToggle( VK_INSERT )
      ::oKeyIns:bMsg = { || ::oKeyIns:lActive := GetKeyToggle( VK_INSERT ), "Ins" }
   endif

   ::CheckTimer()

return nil
#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( SETINSLOCK )
{
   SetKeyLock( VK_INSERT, hb_parl( 1 ) );
}
HB_FUNC( GETCAPSLOCK )
{
   hb_retl( GetKeyLock( VK_CAPITAL ) );
}

#pragma ENDDUMP

Now I can set the insert mode by mouse click or with:
Code: Select all  Expand view
...
KeyToggle( VK_INSERT )
Set( _SET_INSERT, .T. )
...
 

And the NUMLOCK- and CAPSLOCK-LED's on the keyboard are consistent with the FiveWin settings :D
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

Re: KeyToggle() and Num, Caps and Ins keys

Postby karinha » Tue Mar 02, 2021 12:10 pm

Very good!

Regards.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7811
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests