FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour scroll lock
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM
scroll lock
Posted: Mon May 06, 2013 02:47 AM

¿Como puedo detectar y cambiar el estado de scroll lock (creo que generalmente está entre las teclas de imprimir pantalla y break) ?

Saludos

Quique
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: scroll lock
Posted: Mon May 06, 2013 01:20 PM
Quique,

Tienes un ejemplo completo en:
http://msdn.microsoft.com/en-us/library/ms646304%28VS.85%29.aspx

tan sencillo como buscar en google:
scroll lock programmatically check

y lo he encontrado en el segundo resultado :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM
Re: scroll lock
Posted: Tue May 07, 2013 12:08 AM

Gracias Antonio, aunque ahora que lo veo bien, creo que la pregunta no estuvo totalmente clara, porque la idea era detectar el estado, o sea, si el foquito esta preindido o apagado :p , tu respuesta me ayudo bastante, ademas de activar o desactivar el scroll lock, también me ayudara a corregir la barra de mensajes, las secciones caps y num, que no funcionan con el click del ratón.

Pero justificando mi ineptitud por la simplicidad que me dices para encontrar la solución (sin contar que de C solo C que existe, y cuando no lo evito yo, me evita él, por eso buscaba respuesta en fivewin, soy un simple usuario común y corriente, mas corriente que común, de fivewin, el GM eres tu, o que de inglés solo se decir "open the house") mi navegador creo que es mas sope (jerga mexicana, sería algo así como gilipolla por allá) que yo, porque le copié a google lo mismo que pusiste (no se me ocurrió, lo copié de tu respuesta) y me mandó a otras ligas.

Weno, despues del rollote, muchos tenkius :)

Saludos

Quique
Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: scroll lock
Posted: Tue May 07, 2013 03:04 PM
Quique,

Funciona perfecto, enciende y apaga focos num y cap lock:
Code (fw): Select all Collapse
#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);
   }
}


HB_FUNC( KEYTOGGLE ) // ( nVKey )
{
   BYTE pBuffer[ 256 ];
   WORD wKey = hb_parni( 1 );

   GetKeyboardState( pBuffer );

   if( pBuffer[ wKey ] & 0x01 )
      SetKeyLock( wKey, 0 );
   else
      SetKeyLock( wKey, 1 );
  // SetKeyboardState( pBuffer );
}

#pragma ENDDUMP

Saludos,



Carlos Gallego



*** FWH-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: scroll lock
Posted: Tue May 07, 2013 04:22 PM
Mira si ayuda:

Code (fw): Select all Collapse
/*
06/07/07 - Desativar teclas especiais 
  Olá,

Neste exemplo que fiz associado a dll que é encontrada no endereço:

<!-- m --><a class="postlink" href="http://www.codeproject.com/win32/AntonioWinLock.asp">http://www.codeproject.com/win32/AntonioWinLock.asp</a><!-- m -->

...é possível fazer o seguinte em FWH:

- Ativa/Desativar alt+tab
- Ativa/Desativar alt+esc
- Ativa/Desativar ctrl+alt+del
- Mostrar/Esconder a barra de tarefas
- Mostrar/Esconder o desktop
- Mostrar/Esconder o Start Button
- Mostrar/Esconder o System Clock
- Rodar um processo em outro desktop

Espero que gostem :-)

Abraços,

Rossine.
 

esta em ALTTAB.ZIP em dicas mais dicas

==============================================================================

En: 21/08/2008 - Manuel Mercado Gentilmente Converteu Para FIVEWIN FOR XHARBOUR

Hola João

Una conversión rápida del ejemplo de Rossine a su versión en C directamente
con FWH sin Dll's
Manuel Mercado
*/

#Include "FiveWin.Ch"
#Include "Dll.Ch"

Function Teclado() //Main()

/*
   MsgStop( StartButton( .F. ), "Desabilitando o botão Start(Iniciar) - Win 9x, NT, 2K, XP" )

   MsgStop( StartButton( .T. ), "Habilitando   o botão Start(Iniciar) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowDesktop( .F. ), "Desabilitando o Desktop - Win 9x, NT, 2K, XP" )

   MsgStop( DesktopProc( "MyDesktop2", "Calc.exe" ), "Executando uma tarefa em outro desktop - Win NT, 2K, XP" )

   MsgStop( ShowDesktop( .T. ), "Habilitando o Desktop - Win 9x, NT, 2K, XP" )

   MsgStop( ShowTaskbar( .F. ), "Desabilitando o Taskbar(Barra de Tarefas) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowTaskbar( .T. ), "Habilitando   o Taskbar(Barra de Tarefas) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowClock( .F. ), "Desabilitando o Clock(Relogio) - Win 9x, NT, 2K, XP" )

   MsgStop( ShowClock( .T. ), "Habilitando o Clock(Relogio) - Win 9x, NT, 2K, XP" )

   MsgStop( AltTabEnable( 0, .F. ), "Desabilitando ALT+TAB e ALT+ESC - Windows NT, 2k" )

   MsgStop( AltTabEnable( 0, .T. ), "Habilitando   ALT+TAB e ALT+ESC - Windows NT, 2k" )

   // Para Windows XP/NT e 2000 / 2003
   IF IsWinNT() .OR. IsWin2000()  //??? Nao testei em 2000/2003

       MsgStop( CtrlAltDel( .F. ), "Desabilitando o Ctrl+Alt+Del - Windows NT, 2k" )

       MsgStop( CtrlAltDel( .T. ), "Habilitando   o Ctrl+Alt+Del - Windows NT, 2k" )

   ELSE  //-> Windows 95/98 - Millenium Edition

      Ctrl_Alt_Del( .f. )

      MsgAlert( "CTRL+ALT+DEL DESLIGADO" + CRLF + "Please, press CTRL + ALT + DEL", "Desligado" )

      Ctrl_Alt_Del( .t. )

      MsgAlert( "CTRL+ALT+DEL LIGADO" + CRLF + "Please, press CTRL + ALT + DEL", "Ligado" )

   ENDIF
*/

Return Nil
//
//-> Comentario: Simplesmente, FANTASTICO!!!
//
//-> Complementando para Windows 95/98 Milleniun Edition
//
// Antonio Carlos Pantaglione
// <!-- e --><a href="mailto:Toninho@fwi.com.br">Toninho@fwi.com.br</a><!-- e -->
// Agosto/2001
//

//#include "fivewin.ch"
//#include "dll.ch"

//----------------------------------------------------------------------------//

//-> Modifiquei para nao ter choque com a funcao par o Windows NT(XP)
Function Ctrl_Alt_Del( lState )

   if !lState
      SysParInfo( 97, 1, 0, 0 )
   else
      SysParInfo( 97, 0, 0, 0 )
   endif

return Nil

//----------------------------------------------------------------------------//

dll32 static function SysParInfo( uAction AS LONG, uParam AS LONG, vParam AS LONG, uWinIni AS LONG ) ;
      AS LONG PASCAL  FROM "SystemParametersInfoA" LIB "User32.dll"

//----------------------------------------------------------------------------//

//-> Rotina em C -> By Manuel Mercado - The Best

#pragma BEGINDUMP

#include    <windows.h>
#include    <stdlib.h>
#include    <hbapi.h>
#define     ID_STARTBUTTON  0x130                  // Start button ID
#define     ID_TRAY         0x12F                  // System tray ID
#define     ID_CLOCK        0x12F                  // System clock ID
#define     PROGRAM_MANAGER "Program Manager"   // Program manager window name
#define     TASKBAR         "Shell_TrayWnd"     // Taskbar class name

int WINAPI TaskManager_Enable_Disable( BOOL ) ;
int WINAPI StartButton_Show_Hide( BOOL ) ;
int WINAPI Desktop_Show_Hide( BOOL ) ;
int WINAPI Process_Desktop(char *, char * ) ;
int WINAPI Taskbar_Show_Hide( BOOL ) ;
int WINAPI Clock_Show_Hide( BOOL ) ;
int WINAPI AltTab_Enable_Disable( HWND, BOOL ) ;
BOOL StartProcess( char *, char * ) ;
LRESULT CALLBACK LowLevelMouseHookProc( int nCode, WORD wParam, DWORD lParam ) ;
LRESULT CALLBACK MouseHookProc( int nCode, WORD wParam, DWORD lParam ) ;

HHOOK       hHook ;          // Mouse hook
HINSTANCE   hInst ;         // Instance handle

HB_FUNC( ALTTABENABLE )
{
   HWND hWnd    = (HWND ) hb_parnl( 1 ) ;
   BOOL bEnable = hb_parl( 2 ) ;
   int iRet ;

   iRet = AltTab_Enable_Disable( hWnd, bEnable ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( SHOWCLOCK )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = Clock_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( SHOWTASKBAR )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = Taskbar_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( DESKTOPPROC )
{
   char* c1 = hb_parc( 1 ) ;
   char* c2 = hb_parc( 2 ) ;
   int iRet ;

   iRet = Process_Desktop( c1, c2 ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( SHOWDESKTOP )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = Desktop_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( STARTBUTTON )
{
   BOOL bShow = hb_parl( 1 ) ;
   int iRet ;

   iRet = StartButton_Show_Hide( bShow ) ;
   hb_retni( iRet ) ;
}

HB_FUNC( CTRLALTDEL )
{
   BOOL bEnable = hb_parl( 1 ) ;
   int iRet ;

   iRet = TaskManager_Enable_Disable( bEnable ) ;
   hb_retni( iRet ) ;
}

int WINAPI TaskManager_Enable_Disable(BOOL bEnableDisable)
{
    #define KEY_DISABLETASKMGR  "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"
    #define VAL_DISABLETASKMGR  "DisableTaskMgr"

    HKEY    hKey;
    DWORD   val;
    LONG    r;

    if (RegOpenKey(HKEY_CURRENT_USER, KEY_DISABLETASKMGR, &hKey) != ERROR_SUCCESS)
        if (RegCreateKey(HKEY_CURRENT_USER, KEY_DISABLETASKMGR, &hKey) != ERROR_SUCCESS)
            return 0;

    if (bEnableDisable) // Enable
    {
        r = RegDeleteValue(hKey, VAL_DISABLETASKMGR);
    }
    else                // Disable
    {
        val = 1;
        r = RegSetValueEx(hKey, VAL_DISABLETASKMGR, 0, REG_DWORD, (BYTE *)&val, sizeof(val));
    }

    RegCloseKey(hKey);

    return (r == ERROR_SUCCESS ? 1 : 0) ;
}

int WINAPI StartButton_Show_Hide( BOOL bShowHide )
{
    HWND    hWnd;

    hWnd = GetDlgItem( FindWindow( TASKBAR, NULL ), ID_STARTBUTTON ) ;
    if ( hWnd == NULL )
       return 0 ;

    ShowWindow( hWnd, bShowHide ? SW_SHOW : SW_HIDE) ;
    UpdateWindow( hWnd );

    return 1 ;
}

int WINAPI Taskbar_Show_Hide( BOOL bShowHide )
{
    HWND    hWnd;

    hWnd = FindWindow( TASKBAR, NULL ) ;
    if ( hWnd == NULL )
        return 0 ;

    ShowWindow( hWnd, bShowHide ? SW_SHOW : SW_HIDE ) ;
    UpdateWindow(hWnd) ;

    return 1 ;
}

int WINAPI Desktop_Show_Hide( BOOL bShowHide )
{
    OSVERSIONINFO   osvi ;
    BOOL            bIsWindowsNT4SP3orLater ;
    int             iServicePack ;
    char           *p ;

    // Determine the current windows version
    osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ) ;
    GetVersionEx( &osvi );
    for (p = osvi.szCSDVersion; *p  && ! isdigit( *p ) ; *p++ ) ;
    iServicePack = atoi( p ) ;
    bIsWindowsNT4SP3orLater = ( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
                               ( ( ( osvi.dwMajorVersion == 4 ) && ( iServicePack >= 3 ) ) ||
                                     ( osvi.dwMajorVersion > 4 ) ) ;

    if ( ! bShowHide )
    {
        if ( ! hHook )
        {
            hHook  = SetWindowsHookEx( bIsWindowsNT4SP3orLater ? WH_MOUSE_LL : WH_MOUSE,
                                      bIsWindowsNT4SP3orLater ? ( HOOKPROC )LowLevelMouseHookProc : ( HOOKPROC )MouseHookProc,
                             hInst, 0 ) ;
            if ( ! hHook )
                return 0 ;
        }
    }
    else
    {
        UnhookWindowsHookEx(hHook);
        hHook = NULL;
    }

    return SetWindowPos( FindWindow( NULL, PROGRAM_MANAGER ), NULL, 0, 0, 0, 0,
                        bShowHide ? SWP_SHOWWINDOW : SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
}

LRESULT CALLBACK LowLevelMouseHookProc( int nCode, WORD wParam, DWORD lParam )
{
    PMSLLHOOKSTRUCT p = (PMSLLHOOKSTRUCT)lParam ;
    HWND hWnd = WindowFromPoint( p->pt ) ;

    if( nCode >= 0 )
    {
        if ( ( wParam == WM_LBUTTONDOWN || wParam == WM_RBUTTONDOWN ) && hWnd == GetDesktopWindow() )
        {
            return 1 ;
        }
    }

    return CallNextHookEx( hHook, nCode, wParam, lParam ) ;
}

LRESULT CALLBACK MouseHookProc( int nCode, WORD wParam, DWORD lParam )
{
    if( nCode >= 0 )
    {
        if ( wParam == WM_LBUTTONDBLCLK )
        {
            if ( ( ( MOUSEHOOKSTRUCT * )lParam )->hwnd == GetDesktopWindow() )
            {
                return 1 ;
            }
        }
    }

    return CallNextHookEx( hHook, nCode, wParam, lParam ) ;
}

int WINAPI Process_Desktop(char *szDesktopName, char *szPath )
{
    HDESK   hOriginalThread ;
    HDESK   hOriginalInput ;
    HDESK   hNewDesktop ;

    // Save original ...
    hOriginalThread = GetThreadDesktop( GetCurrentThreadId() ) ;
    hOriginalInput = OpenInputDesktop( 0, FALSE, DESKTOP_SWITCHDESKTOP ) ;

    // Create a new Desktop and switch to it
    hNewDesktop = CreateDesktop( szDesktopName, NULL, NULL, 0, GENERIC_ALL, NULL ) ;
    SetThreadDesktop( hNewDesktop ) ;
    SwitchDesktop( hNewDesktop ) ;

    // Execute process in new desktop
    StartProcess( szDesktopName, szPath ) ;

    // Restore original ...
    SwitchDesktop( hOriginalInput ) ;
    SetThreadDesktop( hOriginalThread ) ;

    // Close the Desktop
    CloseDesktop( hNewDesktop ) ;

    return 0 ;
}

BOOL StartProcess( char *szDesktopName, char *szPath )
{
    STARTUPINFO         si ;
    PROCESS_INFORMATION pi ;

    // Zero these structs
    ZeroMemory( &si, sizeof( si ) ) ;
    si.cb = sizeof( si ) ;
     si.lpTitle = szDesktopName ;
     si.lpDesktop = szDesktopName ;
    ZeroMemory( &pi, sizeof( pi ) ) ;

    // Start the child process
    if (!CreateProcess( NULL,    // No module name (use command line).
                        szPath,  // Command line.
                        NULL,    // Process handle not inheritable.
                        NULL,    // Thread handle not inheritable.
                        FALSE,   // Set handle inheritance to FALSE.
                        0,       // No creation flags.
                        NULL,    // Use parent's environment block.
                        NULL,    // Use parent's starting directory.
                        &si,     // Pointer to STARTUPINFO structure.
                        &pi ) )  // Pointer to PROCESS_INFORMATION structure.
    {
        return FALSE ;
    }

    // Wait until process exits
    WaitForSingleObject( pi.hProcess, INFINITE ) ;

    // Close process and thread handles
    CloseHandle( pi.hProcess ) ;
    CloseHandle( pi.hThread ) ;

    return TRUE ;
}

int WINAPI Clock_Show_Hide( BOOL bShowHide )
{
    HWND    hWnd ;

    hWnd = GetDlgItem( FindWindow( TASKBAR, NULL ), ID_TRAY ) ;
     hWnd = GetDlgItem( hWnd, ID_CLOCK ) ;
    if ( hWnd == NULL )
        return 0 ;

    ShowWindow( hWnd, bShowHide ? SW_SHOW : SW_HIDE ) ;
    UpdateWindow( hWnd ) ;

    return 1 ;
}

int WINAPI AltTab_Enable_Disable( HWND hWnd, BOOL bEnableDisable )
{
    #define m_nHotKeyID 100

    if ( ! bEnableDisable )
    {
        if ( ! RegisterHotKey( hWnd, m_nHotKeyID+0, MOD_ALT, VK_TAB ) )     // Alt+Tab
            return 0 ;
      if ( ! RegisterHotKey( hWnd, m_nHotKeyID+1, MOD_ALT, VK_ESCAPE ) )    // Alt+Esc
            return 0 ;
    }
    else
    {
        if ( ! UnregisterHotKey( hWnd, m_nHotKeyID + 0 ) )
            return 0 ;
        if ( ! UnregisterHotKey( hWnd, m_nHotKeyID + 1 ) )
            return 0 ;
    }
    return 1 ;
}
#pragma ENDDUMP

/*
Saludos

Manuel Mercado
*/
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM
Re: scroll lock
Posted: Wed May 08, 2013 01:42 AM

Carlos, muchas gracias, la solución que encontró Antonio no siempre funcionaba bien (o no supe implementarla) pero de repente dejaba de funcionar, con la solución que das no me falló en todas las pruebas que hice :)

Karinha, tu mensaje está muy interesante, aunque no funcionaron todas las opciones, pero me pareció muy interesante para tomarlo en cuenta.

Saludos

Quique

Continue the discussion