Hi.
I would like to intercept the "PrtScrn" key when it's pressed by the user.
I suppose that the key code is VK_SNAPSHOT, please correct me if I am wrong.
But seems that Windows intercepts it first and FiveWin don't get that it was pressed.
Does anyone knows if is it possible ?
[[]]
Maurício Ventura Faria
Intercept pressing VK_SNAPSHOT ( "PrtScr" )
- Antonio Linares
- Site Admin
- Posts: 42425
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 15 times
- Been thanked: 49 times
- Contact:
Re: Intercept pressing VK_SNAPSHOT ( "PrtScr" )
Dear Mauricio,
Here you have a working example:
Here you have a working example:
Code: Select all | Expand
#include "Fivewin.ch"
function Main()
local oDlg
DisablePrintScreen()
DEFINE DIALOG oDlg
ACTIVATE DIALOG oDlg CENTERED
return nil
#pragma BEGINDUMP
#include <windows.h>
LRESULT CALLBACK KeyboardHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT * p = ( KBDLLHOOKSTRUCT * ) lParam;
if( p->vkCode == VK_SNAPSHOT ) // Print Screen key
{
MessageBeep( -1 );
return 1;
}
}
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
HB_FUNC( DISABLEPRINTSCREEN )
{
HHOOK hHook = SetWindowsHookEx( WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0 );
if( ! hHook )
MessageBox( 0, "can't hook", "warning", 0 );
}
#pragma ENDDUMP
Re: Intercept pressing VK_SNAPSHOT ( "PrtScr" )
Hi Antonio.
Thanks, your sample works.
But sorry, I am not a C guy...
[[]] Maurício Faria
Thanks, your sample works.
But sorry, I am not a C guy...
How do I call a Harbour function, for example MyHbFunc() from the C code ?MessageBeep( -1 ); ==> MyHbFunc()
[[]] Maurício Faria
Re: Intercept pressing VK_SNAPSHOT ( "PrtScr" )
Or, how do I send this key pressing event to the :bKeyDown block of an object ?
- Antonio Linares
- Site Admin
- Posts: 42425
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 15 times
- Been thanked: 49 times
- Contact:
Re: Intercept pressing VK_SNAPSHOT ( "PrtScr" )
Code: Select all | Expand
#include "Fivewin.ch"
static oDlg
function Main()
DisablePrintScreen()
DEFINE DIALOG oDlg
ACTIVATE DIALOG oDlg CENTERED
return nil
function MyHbFunc()
static nTimes := 0
oDlg:SetText( "PrintScreen pressed " + Str( ++nTimes ) )
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <hbvm.h>
LRESULT CALLBACK KeyboardHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if( nCode == HC_ACTION )
{
KBDLLHOOKSTRUCT * p = ( KBDLLHOOKSTRUCT * ) lParam;
if( p->vkCode == VK_SNAPSHOT ) // Print Screen key
{
hb_vmPushSymbol( hb_dynsymSymbol( hb_dynsymFindName( "MYHBFUNC" ) ) );
hb_vmPushNil();
hb_vmDo( 0 );
return 1;
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
HB_FUNC( DISABLEPRINTSCREEN )
{
HHOOK hHook = SetWindowsHookEx( WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0 );
if( ! hHook )
MessageBox( 0, "can't hook", "warning", 0 );
}
#pragma ENDDUMP
- Antonio Linares
- Site Admin
- Posts: 42425
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 15 times
- Been thanked: 49 times
- Contact:
Re: Intercept pressing VK_SNAPSHOT ( "PrtScr" )
> Or, how do I send this key pressing event to the :bKeyDown block of an object ?
Code: Select all | Expand
#include "Fivewin.ch"
static oDlg
function Main()
DisablePrintScreen()
DEFINE DIALOG oDlg
oDlg:bKeyDown = { | nKey | If( nKey == VK_SNAPSHOT, MsgBeep(),) }
ACTIVATE DIALOG oDlg CENTERED
return nil
function MyHbFunc( nKeyDown )
Eval( oDlg:bKeyDown, nKeyDown )
return nil
#pragma BEGINDUMP
#include <windows.h>
#include <hbvm.h>
LRESULT CALLBACK KeyboardHookProc( int nCode, WPARAM wParam, LPARAM lParam )
{
if( nCode == HC_ACTION )
{
KBDLLHOOKSTRUCT * p = ( KBDLLHOOKSTRUCT * ) lParam;
if( wParam == WM_KEYDOWN && p->vkCode == VK_SNAPSHOT ) // Print Screen key on keydown
{
hb_vmPushSymbol( hb_dynsymSymbol( hb_dynsymFindName( "MYHBFUNC" ) ) );
hb_vmPushNil();
hb_vmPushInteger( VK_SNAPSHOT );
hb_vmDo( 1 );
return 1;
}
}
return CallNextHookEx( NULL, nCode, wParam, lParam );
}
HB_FUNC( DISABLEPRINTSCREEN )
{
HHOOK hHook = SetWindowsHookEx( WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0 );
if( ! hHook )
MessageBox( 0, "can't hook", "warning", 0 );
}
#pragma ENDDUMP