I have a problem with reading the status of the Shift, Alt and Control keys in the console window, in case we use the Msg commands (MsgInfo, MsgDebug, etc.) in the code.
Below is a simple example:
Code: Select all
#include <hmg.ch>
PROCEDURE MAIN
REQUEST HB_GT_WIN_DEFAULT
cons_hwnd := GETCONSOLEWINDOW()
SetMode( 25, 80 )
CLS
MsgInfo( "Hello" ) // <-------- Doesn't work with any Msg* :((( Why ?
SetForegroundWindow( cons_hwnd )
SetFocus( cons_hwnd )
DO WHILE .T.
inkey(.1)
@ 2,2 SAY "Alt Key Status " + hb_valToStr( GetKeyState( VK_MENU ) )
@ 3,2 SAY "Shift Key Status " + hb_valToStr( GetKeyState( VK_SHIFT ) )
@ 4,2 SAY "Ctrl Key Status " + hb_valToStr( GetKeyState( VK_CONTROL ) )
@ 6,2 SAY "Left Alt Key Status " + hb_valToStr( GetKeyState( VK_LMENU ) )
@ 7,2 SAY "Left Shift Key Status " + hb_valToStr( GetKeyState( VK_LSHIFT ) )
@ 8,2 SAY "Left Ctrl Key Status " + hb_valToStr( GetKeyState( VK_LCONTROL ) )
@10,2 SAY "Right Alt Key Status " + hb_valToStr( GetKeyState( VK_RMENU ) )
@11,2 SAY "Right Shift Key Status " + hb_valToStr( GetKeyState( VK_RSHIFT ) )
@12,2 SAY "Right Ctrl Key Status " + hb_valToStr( GetKeyState( VK_RCONTROL ) )
@14,2 SAY SPACE ( 20 )
@14,2 SAY IF ( isBit( KbdStat(), 1 ), "Shift ", "") + IF ( isBit( KbdStat(), 3 ), "Ctrl ", "") + IF ( isBit( KbdStat(), 4 ), "Alt", "")
IF LastKey() = 27
Exit
End
EndDo
RETURN
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
#pragma BEGINDUMP
#include "hbapi.h"
#include "hbapiitm.h"
#include <windows.h>
// doesn't work with win32 function GetConsoleWindow()
HWND GetConWin()
{
HWND hwnd;
AllocConsole();
hwnd = FindWindowA("ConsoleWindowClass",NULL);
return hwnd;
}
HB_FUNC( GETCONSOLEWINDOW )
{
hb_retnl((long) GetConWin() );
}
HB_FUNC(HIDECONSOLE )
{
long h = hb_parnl(1);
if (h==NULL)
h = GetConWin();
ShowWindow(h,SW_HIDE); // SW_HIDE
}
HB_FUNC(SHOWCONSOLE )
{
long h = hb_parnl(1);
if (h==NULL)
h = GetConWin();
ShowWindow(h,SW_SHOW); // because 1'st time console stays minimized
ShowWindow(h,SW_RESTORE); //SW_SHOW
SetFocus(h);
SetForegroundWindow(h);
}
#pragma ENDDUMP
/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
Any ideas