elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: 1 ... 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 [660] 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 ... 1236
6591  Programación / Scripting / Re: Cambiar una letra de unidad extraible en batch en: 27 Septiembre 2014, 05:25 am
creí que mi código estaba un poco mal :3

Si, estás usando malas practicas, los Strings deberías encerrarlos de principio a fin, no solamente las partes que contengan espacios, ya que resulta confuso, es bastante irreconocible en cualquier editor de texto (para programadores, no el notepad), y hacer eso no te asegura que no vayas a cometer equivocaciones en el resto del String.

Aparte de eso, si tu intención es crear una variable por cada unidad encontrada entonces no es necesario setear 9 variables especificas, puedes crear las variables que hagan falta en tiempo de ejecución, o crear un menú con ellas, etc.

Te escribo un ejemplo:
Código
  1. @ECHO OFF & (CHCP 1252)1>NUL
  2.  
  3. :: Enumeración 'DriveType' de la Class 'Win32_LogicalDisk' de la Interface WMI.
  4. :: Documentación: http://msdn.microsoft.com/en-us/library/aa394173%28v=vs.85%29.aspx
  5. Set /A "HardDisk=3"
  6. Set /A "RemovableDisk=2"
  7.  
  8. :: Cambio el directorio de trabajo actual.
  9. PUSHD "%SystemRoot%\System32"
  10.  
  11. :: Ejecuto una Query al comando externo WMIC.exe y filtro la salida resultante.
  12. For /F "Delims= " %%# In (
  13.   '.\WBEM\WMIC.exe "logicaldisk" "get" "caption"^,"drivetype" ^| .\FindStr.exe "%HardDisk% %RemovableDisk%"'
  14. ) Do (
  15.   :: Obtengo las letras de los dispositivos conectados.
  16.   Call Set "DRIVES=%%DRIVES%%%%#"
  17. )
  18.  
  19. :: Simple Debug.
  20. REM Echo [Debug] Unidades encontradas: %DRIVES%
  21.  
  22. :: Elimino la letra de unidad desde la que se inició este Script;
  23. :: ya que la letra de la unidad activa (del SO) no se podrá modificar.
  24. :: Doy por hecho que se ejecutó desde la unidad activa del SO, de lo contrario esto necesita un retoque.
  25. Call Set "DRIVES=%%DRIVES:%~d0=%%"
  26.  
  27. :: Reemplazo el caracter ":" del resto de letras por un caracter de "espacio";
  28. :: de esta manera puedo usar el delimitador por defecto ("espacio") en un For.
  29. Set "DRIVES=%DRIVES::= %"
  30.  
  31. :: Por último, proceso cada letra de unidad para crear variables de manera dinámica.
  32. Set "INPUT="
  33. Set /A "Count=0"
  34.  
  35. For %%D in (%DRIVES%) Do (
  36.  
  37.   Set /A "Count+=1"             & REM Incremento el contador.
  38.   Call Set "_%%Count%%=%%D"     & REM Seteo la variable con el número del contador.
  39.   Call Set "INPUT=%%INPUT%%%%D" & REM Asigno la letra de unidad a la variable.
  40.  
  41. )
  42.  
  43. :: Pregunto al usuario por una letra de unidad.
  44. ".\Choice.exe" /C "%INPUT%" /M "Elige una letra de unidad"
  45. Set /A "CHOICE=%ErrorLevel%"   & REM Guardo el resultado.
  46. Call Set "DRIVE=%%_%CHOICE%%%" & REM Seteo la letra de unidad elegida.
  47.  
  48. :: Y manejo la unidad de la forma que se desee:
  49. Call Echo Listado de carpetas: de la unidad "%DRIVE%:\" | .\More.com
  50. Dir /B /AD "%DRIVE%:\*"
  51.  
  52. :: Vuelvo al directorio de trabajo inicial.
  53.  
  54. Pause&Exit /B 0

Saludos
6592  Programación / Scripting / Re: Cambiar una letra de unidad extraible en batch en: 27 Septiembre 2014, 04:01 am
1) Las preguntas sobre Scripts van en esta sección.

2) Los códigos deben publicarse con el formato de código correcto (puedes leer mi firma si no te aclaras)




ya se que con cmd se hace con diskpart pero en batch sé que no será lo mismo, entonces pues ayudenme en mi programita, soy novato pero entenderé lo que estoy copiando

Lo que conoces como CMD es Batch, y lo que conoces como Batch es CMD, el proceso CMD.exe es el intérprete del "lenguaje" Batch (lenguaje entre comillas, porque debido a su simpleza no se considera como tal),
así pues, la CMD (o Command Prompt) es la aplicación encargada de procesar las órdenes/instrucciones que contiene un Script escrito en Batch (o Batch-Script), no hay más de lo que ya hayas visto usando la consola.

Por lo tanto el método a realizar es el mismo, usando la herramienta Diskpart.exe (y también puedes hacerlo con MountVol.exe), ya que Batch debe recurrir a este tipo de aplicaciones externas (o "comandos externos") para ofrecer algún tipo de funcionalidad útil.

Doy por hecho que ya sabes usar diskpart (o que de lo contrario vas a buscar en Google, o a mirar la ayuda del comando Diskpart.exe /? ,  MountVol.exe /?) y no necesitas más ayuda al respecto sabiendo que el procedimiento es exactamente el mismo en Batch, porque te estas refiriendo a eso al hablar de la CMD (en este caso).

Saludos!
6593  Programación / Programación General / MOVIDO: Cambiar una letra de unidad extraible en batch en: 27 Septiembre 2014, 03:48 am
El tema ha sido movido a Scripting.

http://foro.elhacker.net/index.php?topic=422039.0
6594  Programación / Programación General / Re: [EHN-Dev 2014] - Hilo de discusión / comentarios / dudas en: 27 Septiembre 2014, 03:09 am
Una pregunta, ya que he tenido que leer sobre las licencias porque nunca les había puesto interés como tal, según leí, el hecho de que un programa sea Open Source significa que el código sera visible para cualquiera que lo quiera revisar mas no tendrá permiso de modificarlo, ¿cierto?

Hola

Yo no soy experto en el tema de licencias (a diferencia del compañero KuB0x) pero precisamente el "código abierto" significa que cualquier persona tiene permiso a modificar el código fuente (siempre que se respete los términos de la licencia/autor en cuestión)

In production and development, open source as a development model promotes a universal access via a free license to a product's design or blueprint, and universal redistribution of that design or blueprint, including subsequent improvements to it by anyone.

Saludos!
6595  Programación / Scripting / Re: Analizar Ejecutable En Red? en: 26 Septiembre 2014, 22:30 pm
Siguiendo este hilo dentro del foro encontré el programa, alojado en el foro también.. sera segura esa descarga??

Saludos!

Actualizo! No, el programa no esta mas en el foro.. pero si estuvo, seguro alguien lo uso y no reporto bicho raro..  :silbar:

¿Te has fijado en que esa es la versión 0.2, y la de code-google es la 2.0?, 6 años de desarrollo de diferencia entre cada versión...
 tú tranquilo, esa APP no está infectada, creo que se puede descargar el source por SVN, pero aun así tenia que dar un aviso general por la gente que son...

Saludos!
6596  Foros Generales / Foro Libre / Re: ¿Vais a participar en el EHN-Dev 2014? en: 26 Septiembre 2014, 16:44 pm
@erest0r

Por segunda vez:

Porfavor, formular las preguntas en el post que publicó el compañero KuB0x, que para algo está el post.

[EHN-Dev 2014] - Hilo de discusión / comentarios / dudas

Saludos!
6597  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Ejemplo de un LL-Hook para el Mouse. en: 26 Septiembre 2014, 16:41 pm
Otro repaso más a la Class, he añadido una funcionalidad experimental para restringir los eventos que envia la instancia del hook a los límites de un Rectangle (el Rectangle de la pantalla especificada, por ejemplo), lo he testeado en una pantalla normal, así como en Dual-Screen e invirtiendo el orden de la pantalla principal, todo parece haber ido sin irregularidades :).

Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 09-26-2014
  4. ' ***********************************************************************
  5. ' <copyright file="MouseHook.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Instructions "
  11.  
  12. ' Go to page:
  13. ' Project > Properties > Debug
  14. '
  15. ' Then uncheck the option:
  16. ' "Enable the Visual Studio Hosting Process"
  17.  
  18. #End Region
  19.  
  20. #Region " Usage Examples "
  21.  
  22. #End Region
  23.  
  24. #Region " Imports "
  25.  
  26. Imports System.ComponentModel
  27. Imports System.Reflection
  28. Imports System.Runtime.InteropServices
  29.  
  30. #End Region
  31.  
  32. #Region " MouseHook "
  33.  
  34. ''' <summary>
  35. ''' A low level mouse hook that processes mouse input events.
  36. ''' </summary>
  37. Friend NotInheritable Class MouseHook : Implements IDisposable
  38.  
  39. #Region " P/Invoke "
  40.  
  41.    ''' <summary>
  42.    ''' Platform Invocation methods (P/Invoke), access unmanaged code.
  43.    ''' This class does not suppress stack walks for unmanaged code permission.
  44.    ''' <see cref="System.Security.SuppressUnmanagedCodeSecurityAttribute"/>  must not be applied to this class.
  45.    ''' This class is for methods that can be used anywhere because a stack walk will be performed.
  46.    ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/ms182161.aspx
  47.    ''' </summary>
  48.    Protected NotInheritable Class NativeMethods
  49.  
  50. #Region " Methods "
  51.  
  52.        ''' <summary>
  53.        ''' Passes the hook information to the next hook procedure in the current hook chain.
  54.        ''' A hook procedure can call this function either before or after processing the hook information.
  55.        ''' For more info see here:
  56.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644974%28v=vs.85%29.aspx
  57.        ''' </summary>
  58.        ''' <param name="idHook">
  59.        ''' This parameter is ignored.
  60.        ''' </param>
  61.        ''' <param name="nCode">
  62.        ''' The hook code passed to the current hook procedure.
  63.        ''' The next hook procedure uses this code to determine how to process the hook information.
  64.        ''' </param>
  65.        ''' <param name="wParam">
  66.        ''' The wParam value passed to the current hook procedure.
  67.        ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
  68.        ''' </param>
  69.        ''' <param name="lParam">
  70.        ''' The lParam value passed to the current hook procedure.
  71.        ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
  72.        ''' </param>
  73.        ''' <returns>
  74.        ''' This value is returned by the next hook procedure in the chain.
  75.        ''' The current hook procedure must also return this value.
  76.        ''' The meaning of the return value depends on the hook type.
  77.        ''' For more information, see the descriptions of the individual hook procedures.
  78.        ''' </returns>
  79.        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  80.        Friend Shared Function CallNextHookEx(
  81.               ByVal idHook As IntPtr,
  82.               ByVal nCode As Integer,
  83.               ByVal wParam As IntPtr,
  84.               ByVal lParam As IntPtr
  85.        ) As IntPtr
  86.        End Function
  87.  
  88.        ''' <summary>
  89.        ''' Installs an application-defined hook procedure into a hook chain.
  90.        ''' You would install a hook procedure to monitor the system for certain types of events.
  91.        ''' These events are associated either with a specific thread
  92.        ''' or with all threads in the same desktop as the calling thread.
  93.        ''' For more info see here:
  94.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
  95.        ''' </summary>
  96.        ''' <param name="idHook">
  97.        ''' The type of hook procedure to be installed.
  98.        ''' </param>
  99.        ''' <param name="lpfn">
  100.        ''' A pointer to the hook procedure.
  101.        ''' If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process,
  102.        ''' the lpfn parameter must point to a hook procedure in a DLL.
  103.        ''' Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
  104.        ''' </param>
  105.        ''' <param name="hInstance">
  106.        ''' A handle to the DLL containing the hook procedure pointed to by the lpfn parameter.
  107.        ''' The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by
  108.        ''' the current process and if the hook procedure is within the code associated with the current process.
  109.        ''' </param>
  110.        ''' <param name="threadId">
  111.        ''' The identifier of the thread with which the hook procedure is to be associated.
  112.        ''' For desktop apps, if this parameter is zero, the hook procedure is associated
  113.        ''' with all existing threads running in the same desktop as the calling thread.
  114.        ''' </param>
  115.        ''' <returns>
  116.        ''' If the function succeeds, the return value is the handle to the hook procedure.
  117.        ''' If the function fails, the return value is NULL.
  118.        ''' </returns>
  119.        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  120.        Friend Shared Function SetWindowsHookEx(
  121.               ByVal idHook As HookType,
  122.               ByVal lpfn As LowLevelMouseProcDelegate,
  123.               ByVal hInstance As IntPtr,
  124.               ByVal threadId As UInteger
  125.        ) As IntPtr
  126.        End Function
  127.  
  128.        ''' <summary>
  129.        ''' Removes a hook procedure installed in a hook chain by the 'SetWindowsHookEx' function.
  130.        ''' For more info see here:
  131.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644993%28v=vs.85%29.aspx
  132.        ''' </summary>
  133.        ''' <param name="idHook">
  134.        ''' A handle to the hook to be removed.
  135.        ''' This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
  136.        ''' </param>
  137.        ''' <returns>
  138.        ''' If the function succeeds, the return value is nonzero.
  139.        ''' If the function fails, the return value is zero.
  140.        ''' </returns>
  141.        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  142.        Friend Shared Function UnhookWindowsHookEx(
  143.               ByVal idHook As IntPtr
  144.        ) As Boolean
  145.        End Function
  146.  
  147.        ''' <summary>
  148.        ''' Retrieves the current double-click time for the mouse.
  149.        ''' A double-click is a series of two clicks of the mouse button,
  150.        ''' the second occurring within a specified time after the first.
  151.        ''' The double-click time is the maximum number of milliseconds that may occur
  152.        ''' between the first and second click of a double-click.
  153.        ''' The maximum double-click time is 5000 milliseconds.
  154.        ''' </summary>
  155.        ''' <returns>
  156.        ''' The return value specifies the current double-click time, in milliseconds.
  157.        ''' The maximum return value is 5000 milliseconds.
  158.        ''' </returns>
  159.        <DllImport("user32.dll", CharSet:=CharSet.Auto)>
  160.        Friend Shared Function GetDoubleClickTime() As Integer
  161.        End Function
  162.  
  163. #End Region
  164.  
  165. #Region " Enumerations "
  166.  
  167.        ''' <summary>
  168.        ''' Indicates a type of Hook procedure to be installed.
  169.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
  170.        ''' </summary>
  171.        <Description("Enum used in 'idHook' parameter of 'SetWindowsHookEx' function.")>
  172.        Friend Enum HookType As UInteger
  173.  
  174.            ' **************************************
  175.            ' This enumeration is partially defined.
  176.            ' **************************************
  177.  
  178.            ''' <summary>
  179.            ''' Installs a hook procedure that monitors low-level mouse input events.
  180.            ''' For more information, see the LowLevelMouseProc hook procedure.
  181.            ''' </summary>
  182.            WH_MOUSE_LL = 14UI
  183.  
  184.        End Enum
  185.  
  186.        ''' <summary>
  187.        ''' The event-injected flags.
  188.        ''' An application can use the following values to test the flags.
  189.        ''' Testing LLMHF_INJECTED (bit 0) will tell you whether the event was injected.
  190.        ''' If it was, then testing LLMHF_LOWER_IL_INJECTED (bit 1) will tell you
  191.        ''' whether or not the event was injected from a process running at lower integrity level.
  192.        ''' </summary>
  193.        <Flags()>
  194.        <Description("Enum used in 'flags' parameter of 'MSLLHOOKSTRUCT' structure.")>
  195.        Public Enum MSLLHOOKSTRUCTFlags As Integer
  196.  
  197.            ''' <summary>
  198.            ''' Test the event-injected (from any process) flag.
  199.            ''' </summary>
  200.            LLMHF_INJECTED = 1I
  201.  
  202.            ''' <summary>
  203.            ''' Test the event-injected (from a process running at lower integrity level) flag.
  204.            ''' </summary>
  205.            LLMHF_LOWER_IL_INJECTED = 2I
  206.  
  207.        End Enum
  208.  
  209. #End Region
  210.  
  211. #Region " Structures "
  212.  
  213.        ''' <summary>
  214.        ''' The POINT structure defines the x- and y- coordinates of a point.
  215.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162805%28v=vs.85%29.aspx
  216.        ''' </summary>
  217.        <Description("Structure used in 'pt' parameter of 'MSLLHOOKSTRUCT' structure.")>
  218.        <StructLayout(LayoutKind.Sequential)>
  219.        Friend Structure POINT
  220.  
  221.            ''' <summary>
  222.            ''' The x-coordinate of the point.
  223.            ''' </summary>
  224.            Friend X As Integer
  225.  
  226.            ''' <summary>
  227.            ''' The y-coordinate of the point.
  228.            ''' </summary>
  229.            Friend Y As Integer
  230.  
  231.        End Structure
  232.  
  233.        ''' <summary>
  234.        ''' Contains information about a low-level mouse input event.
  235.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644970%28v=vs.85%29.aspx
  236.        ''' </summary>
  237.        <Description("Structure used in 'lParam' parameter of 'CallNextHookEx' function.")>
  238.        Friend Structure MSLLHOOKSTRUCT
  239.  
  240.            ''' <summary>
  241.            ''' The ptThe x- and y-coordinates of the cursor, in screen coordinates.
  242.            ''' </summary>
  243.            Friend pt As NativeMethods.POINT
  244.  
  245.            ''' <summary>
  246.            ''' If the message is 'WM_MOUSEWHEEL', the high-order word of this member is the wheel delta.
  247.            ''' The low-order word is reserved.
  248.            ''' A positive value indicates that the wheel was rotated forward, away from the user;
  249.            ''' a negative value indicates that the wheel was rotated backward, toward the user.
  250.            ''' One wheel click is defined as 'WHEEL_DELTA', which is '120'.
  251.            ''' </summary>
  252.            Friend mouseData As Integer
  253.  
  254.            ''' <summary>
  255.            ''' The event-injected flag.
  256.            ''' </summary>
  257.            Friend flags As MSLLHOOKSTRUCTFlags
  258.  
  259.            ''' <summary>
  260.            ''' The time stamp for this message.
  261.            ''' </summary>
  262.            Friend time As UInteger
  263.  
  264.            ''' <summary>
  265.            ''' Additional information associated with the message.
  266.            ''' </summary>
  267.            Friend dwExtraInfo As IntPtr
  268.  
  269.        End Structure
  270.  
  271. #End Region
  272.  
  273. #Region " Delegates "
  274.  
  275.        ''' <summary>
  276.        ''' Delegate LowLevelMouseProc
  277.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx
  278.        ''' </summary>
  279.        ''' <returns>
  280.        ''' If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
  281.        ''' If nCode is greater than or equal to zero, and the hook procedure did not process the message,
  282.        ''' it is highly recommended that you call CallNextHookEx and return the value it returns;
  283.        ''' otherwise, other applications that have installed WH_MOUSE_LL hooks will not receive hook notifications
  284.        ''' and may behave incorrectly as a result.
  285.        ''' If the hook procedure processed the message,
  286.        ''' it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure.
  287.        ''' </returns>
  288.        Friend Delegate Function LowLevelMouseProcDelegate(
  289.                ByVal nCode As IntPtr,
  290.                ByVal wParam As IntPtr,
  291.                ByVal lParam As IntPtr
  292.        ) As Integer
  293.  
  294. #End Region
  295.  
  296. #Region " Hidden Methods "
  297.  
  298.        ''' <summary>
  299.        ''' Determines whether the specified System.Object instances are considered equal.
  300.        ''' </summary>
  301.        <EditorBrowsable(EditorBrowsableState.Never)>
  302.        Public Shadows Sub Equals()
  303.        End Sub
  304.  
  305.        ''' <summary>
  306.        ''' Determines whether the specified System.Object instances are the same instance.
  307.        ''' </summary>
  308.        <EditorBrowsable(EditorBrowsableState.Never)>
  309.        Private Shadows Sub ReferenceEquals()
  310.        End Sub
  311.  
  312. #End Region
  313.  
  314.    End Class
  315.  
  316. #End Region
  317.  
  318. #Region " Objects "
  319.  
  320.    ''' <summary>
  321.    ''' Handle to the hook procedure.
  322.    ''' </summary>
  323.    Private MouseHook As IntPtr
  324.  
  325.    ''' <summary>
  326.    ''' The mouse hook delegate.
  327.    ''' </summary>
  328.    Private MouseHookDelegate As NativeMethods.LowLevelMouseProcDelegate
  329.  
  330. #End Region
  331.  
  332. #Region " Properties "
  333.  
  334.    ''' <summary>
  335.    ''' ** ONLY FOR TESTING PURPOSES **
  336.    ''' Gets or sets a value indicating whether to suppress the last MouseUp event of
  337.    ''' the specified clicked button when a double-click fires.
  338.    '''
  339.    ''' If this value is set to <c>true</c>, the application will send the events in this order for a Double-Click:
  340.    ''' MouseDown, MouseUp, MouseDown, MouseDoubleClick
  341.    '''
  342.    ''' If this value is set to <c>false</c>, the application will send the events in this order for a Double-Click:
  343.    ''' MouseDown, MouseUp, MouseDown, MouseUp, MouseDoubleClick
  344.    '''
  345.    ''' </summary>
  346.    ''' <value><c>true</c> if MouseUp event is suppressed; otherwise <c>false</c>.</value>
  347.    Friend Property SuppressMouseUpEventWhenDoubleClick As Boolean = False
  348.  
  349.    ''' <summary>
  350.    ''' ** ONLY FOR TESTING PURPOSES **
  351.    ''' Gets or sets the screen's working area.
  352.    ''' The events fired by <see cref="MouseHook"/> are restricted to the bounds of the specified rectangle.
  353.    ''' </summary>
  354.    ''' <value>The screen's working area.</value>
  355.    Friend Property WorkingArea As Rectangle
  356.        Get
  357.            Return Me._Workingarea
  358.        End Get
  359.        Set(ByVal value As Rectangle)
  360.            Me._Workingarea = value
  361.        End Set
  362.    End Property
  363.  
  364.    ''' <summary>
  365.    ''' The screen's working area
  366.    ''' </summary>
  367.    Private _Workingarea As Rectangle = SystemInformation.VirtualScreen
  368.  
  369. #End Region
  370.  
  371. #Region " Enumerations "
  372.  
  373.    ''' <summary>
  374.    ''' Indicates a Windows Message related to a mouse events.
  375.    ''' For more info see here:
  376.    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ff468877%28v=vs.85%29.aspx
  377.    ''' </summary>
  378.    Private Enum MouseMessages As UInteger
  379.  
  380.        ''' <summary>
  381.        ''' Posted to a window when the cursor moves.
  382.        ''' If the mouse is not captured, the message is posted to the window that contains the cursor.
  383.        ''' Otherwise, the message is posted to the window that has captured the mouse
  384.        ''' </summary>
  385.        WM_MOUSEMOVE = &H200UI
  386.  
  387.        ''' <summary>
  388.        ''' Posted when the user presses the left mouse button while the cursor is in the client area of a window.
  389.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  390.        ''' Otherwise, the message is posted to the window that has captured the mouse
  391.        ''' </summary>
  392.        WM_LBUTTONDOWN = &H201UI
  393.  
  394.        ''' <summary>
  395.        ''' Posted when the user releases the left mouse button while the cursor is in the client area of a window.
  396.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  397.        ''' Otherwise, the message is posted to the window that has captured the mouse
  398.        ''' </summary>
  399.        WM_LBUTTONUP = &H202UI
  400.  
  401.        ''' <summary>
  402.        ''' Posted when the user presses the right mouse button while the cursor is in the client area of a window.
  403.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  404.        ''' Otherwise, the message is posted to the window that has captured the mouse
  405.        ''' </summary>
  406.        WM_RBUTTONDOWN = &H204UI
  407.  
  408.        ''' <summary>
  409.        ''' Posted when the user releases the right mouse button while the cursor is in the client area of a window.
  410.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  411.        ''' Otherwise, the message is posted to the window that has captured the mouse
  412.        ''' </summary>
  413.        WM_RBUTTONUP = &H205UI
  414.  
  415.        ''' <summary>
  416.        ''' Posted when the user presses the middle mouse button while the cursor is in the client area of a window.
  417.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  418.        ''' Otherwise, the message is posted to the window that has captured the mouse
  419.        ''' </summary>
  420.        WM_MBUTTONDOWN = &H207UI
  421.  
  422.        ''' <summary>
  423.        ''' Posted when the user releases the middle mouse button while the cursor is in the client area of a window.
  424.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  425.        ''' Otherwise, the message is posted to the window that has captured the mouse
  426.        ''' </summary>
  427.        WM_MBUTTONUP = &H208UI
  428.  
  429.        ''' <summary>
  430.        ''' Sent to the active window when the mouse's horizontal scroll wheel is tilted or rotated.
  431.        ''' The DefWindowProc function propagates the message to the window's parent.
  432.        ''' There should be no internal forwarding of the message,
  433.        ''' since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
  434.        ''' </summary>
  435.        WM_MOUSEWHEEL = &H20AUI
  436.  
  437.    End Enum
  438.  
  439.    ''' <summary>
  440.    ''' Indicates the whell direction of the mouse.
  441.    ''' </summary>
  442.    Public Enum WheelDirection As Integer
  443.  
  444.        ''' <summary>
  445.        ''' The wheel is moved up.
  446.        ''' </summary>
  447.        WheelUp = 1I
  448.  
  449.        ''' <summary>
  450.        ''' The wheel is moved down.
  451.        ''' </summary>
  452.        WheelDown = 2I
  453.  
  454.    End Enum
  455.  
  456. #End Region
  457.  
  458. #Region " Events "
  459.  
  460.    ''' <summary>
  461.    ''' Occurs when the mouse moves.
  462.    ''' </summary>
  463.    Friend Event MouseMove(ByVal sender As Object,
  464.                           ByVal MouseLocation As Point)
  465.  
  466.    ''' <summary>
  467.    ''' Occurs when the mouse left button is pressed.
  468.    ''' </summary>
  469.    Friend Event MouseLeftDown(ByVal sender As Object,
  470.                               ByVal MouseLocation As Point)
  471.  
  472.    ''' <summary>
  473.    ''' Occurs when the mouse left button is released.
  474.    ''' </summary>
  475.    Friend Event MouseLeftUp(ByVal sender As Object,
  476.                             ByVal MouseLocation As Point)
  477.  
  478.    ''' <summary>
  479.    ''' Occurs when the mouse left button performs a double-click.
  480.    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
  481.    ''' </summary>
  482.    Friend Event MouseLeftDoubleClick(ByVal sender As Object,
  483.                                      ByVal MouseLocation As Point)
  484.  
  485.    ''' <summary>
  486.    ''' Occurs when the mouse right button is pressed.
  487.    ''' </summary>
  488.    Friend Event MouseRightDown(ByVal sender As Object,
  489.                                ByVal MouseLocation As Point)
  490.  
  491.    ''' <summary>
  492.    ''' Occurs when the mouse right button is released.
  493.    ''' </summary>
  494.    Friend Event MouseRightUp(ByVal sender As Object,
  495.                              ByVal MouseLocation As Point)
  496.  
  497.    ''' <summary>
  498.    ''' Occurs when the mouse right button performs a double-click.
  499.    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
  500.    ''' </summary>
  501.    Friend Event MouseRightDoubleClick(ByVal sender As Object,
  502.                                       ByVal MouseLocation As Point)
  503.  
  504.    ''' <summary>
  505.    ''' Occurs when the mouse middle button is pressed.
  506.    ''' </summary>
  507.    Friend Event MouseMiddleDown(ByVal sender As Object,
  508.                                 ByVal MouseLocation As Point)
  509.  
  510.    ''' <summary>
  511.    ''' Occurs when the mouse middle button is released.
  512.    ''' </summary>
  513.    Friend Event MouseMiddleUp(ByVal sender As Object,
  514.                               ByVal MouseLocation As Point)
  515.  
  516.    ''' <summary>
  517.    ''' Occurs when the mouse middle button performs a double-click.
  518.    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
  519.    ''' </summary>
  520.    Friend Event MouseMiddleDoubleClick(ByVal sender As Object,
  521.                                        ByVal MouseLocation As Point)
  522.  
  523.    ''' <summary>
  524.    ''' Occurs when the mouse wheel is moved up or down.
  525.    ''' </summary>
  526.    Friend Event MouseWheel(ByVal sender As Object,
  527.                            ByVal MouseLocation As Point,
  528.                            ByVal WheelDirection As WheelDirection)
  529.  
  530. #End Region
  531.  
  532. #Region " Constructors "
  533.  
  534.    ''' <summary>
  535.    ''' Prevents a default instance of the <see cref="MouseHook"/> class from being created.
  536.    ''' </summary>
  537.    Private Sub New()
  538.    End Sub
  539.  
  540.    ''' <summary>
  541.    ''' Initializes a new instance of the <see cref="MouseHook"/> class.
  542.    ''' </summary>
  543.    ''' <param name="Install">
  544.    ''' If set to <c>true</c>, the Hook starts initialized for this <see cref="MouseHook"/> instance.
  545.    ''' </param>
  546.    Friend Sub New(Optional ByVal Install As Boolean = False)
  547.  
  548.        If Install Then
  549.            Me.Install()
  550.        End If
  551.  
  552.    End Sub
  553.  
  554. #End Region
  555.  
  556. #Region " Public Methods "
  557.  
  558.    ''' <summary>
  559.    ''' Installs the Mouse Hook, then start processing messages to fire events.
  560.    ''' </summary>
  561.    Friend Sub Install()
  562.  
  563.        Me.MouseHookDelegate = New NativeMethods.LowLevelMouseProcDelegate(AddressOf LowLevelMouseProc)
  564.  
  565.        Try
  566.            Me.MouseHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL,
  567.                                                          Me.MouseHookDelegate,
  568.                                                          Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
  569.  
  570.        Catch ex As Exception
  571.            Throw
  572.  
  573.        End Try
  574.  
  575.    End Sub
  576.  
  577.    ''' <summary>
  578.    ''' Uninstalls the Mouse Hook and free all resources, then stop processing messages to fire events.
  579.    ''' </summary>
  580.    Friend Sub Uninstall()
  581.  
  582.        Me.Finalize()
  583.  
  584.    End Sub
  585.  
  586. #End Region
  587.  
  588. #Region " Private Methods "
  589.  
  590.    ''' <summary>
  591.    ''' Processes the mouse windows messages and raises it's corresponding events.
  592.    ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx
  593.    ''' </summary>
  594.    ''' <param name="nCode">
  595.    ''' A code the hook procedure uses to determine how to process the message.
  596.    ''' If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function
  597.    ''' without further processing and should return the value returned by CallNextHookEx.
  598.    ''' </param>
  599.    ''' <param name="wParam">The identifier of the mouse message.</param>
  600.    ''' <param name="lParam"> A pointer to an <see cref="NativeMethods.MSLLHOOKSTRUCT"/> structure.</param>
  601.    ''' <returns>
  602.    ''' If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
  603.    ''' If nCode is greater than or equal to zero, and the hook procedure did not process the message,
  604.    ''' it is highly recommended that you call CallNextHookEx and return the value it returns;
  605.    ''' otherwise, other applications that have installed WH_MOUSE_LL hooks will not receive hook notifications
  606.    ''' and may behave incorrectly as a result.
  607.    ''' If the hook procedure processed the message,
  608.    ''' it may return a nonzero value to prevent the system from passing the
  609.    ''' message to the rest of the hook chain or the target window procedure.
  610.    ''' </returns>
  611.    Private Function LowLevelMouseProc(ByVal nCode As Integer,
  612.                                       ByVal wParam As MouseMessages,
  613.                                       ByVal lParam As IntPtr) As Integer
  614.  
  615.        Static LeftClickTime As Integer = 0I ' Determines a left button double-click.
  616.        Static RightClickTime As Integer = 0I ' Determines a right button double-click.
  617.        Static MiddleClickTime As Integer = 0I ' Determines a middle button double-click.
  618.  
  619.        If nCode = 0I Then
  620.  
  621.            Dim x As Integer
  622.            Dim y As Integer
  623.  
  624.            Dim MouseStruct As NativeMethods.MSLLHOOKSTRUCT
  625.            MouseStruct = CType(Marshal.PtrToStructure(lParam, MouseStruct.GetType()),
  626.                                NativeMethods.MSLLHOOKSTRUCT)
  627.  
  628.            ' Fix X coordinate.
  629.            Select Case MouseStruct.pt.X
  630.  
  631.                Case Is <= 0I
  632.                    If MouseStruct.pt.X >= Me.WorkingArea.Location.X Then
  633.                        x = MouseStruct.pt.X
  634.  
  635.                    ElseIf MouseStruct.pt.X <= Me.WorkingArea.Location.X Then
  636.  
  637.                        If MouseStruct.pt.X <= (Me.WorkingArea.Location.X - Me.WorkingArea.Width) Then
  638.                            x = (Me.WorkingArea.Location.X - Me.WorkingArea.Width)
  639.                        Else
  640.                            x = MouseStruct.pt.X
  641.                        End If
  642.  
  643.                    End If
  644.  
  645.                Case Is >= Me.WorkingArea.Width
  646.                    x = Me.WorkingArea.Width
  647.  
  648.                Case Else
  649.                    x = MouseStruct.pt.X
  650.  
  651.            End Select
  652.  
  653.            ' Fix Y coordinate.
  654.            Select Case MouseStruct.pt.Y
  655.  
  656.                Case Is >= Me.WorkingArea.Height
  657.                    y = Me.WorkingArea.Height
  658.  
  659.                Case Is <= 0I
  660.                    y = 0I
  661.  
  662.                Case Else
  663.                    y = MouseStruct.pt.Y
  664.  
  665.            End Select
  666.  
  667.            If x <= Me.WorkingArea.Width _
  668.            AndAlso y < Me.WorkingArea.Height _
  669.            AndAlso MouseStruct.pt.X > Me.WorkingArea.Width Then
  670.  
  671.                Return 0
  672.  
  673.            ElseIf x <= Me.WorkingArea.Width _
  674.            AndAlso y < Me.WorkingArea.Height _
  675.            AndAlso MouseStruct.pt.X < Me.WorkingArea.X Then
  676.  
  677.                Return 0
  678.  
  679.            ElseIf x = Me.WorkingArea.Width _
  680.            AndAlso y < Me.WorkingArea.Height Then
  681.  
  682.                If Not Me.WorkingArea.Contains(x - 1, y) Then
  683.                    Return 0
  684.                End If
  685.  
  686.            ElseIf x < Me.WorkingArea.Width _
  687.            AndAlso y = Me.WorkingArea.Height Then
  688.  
  689.                If Not Me.WorkingArea.Contains(x, y - 1) Then
  690.                    Return 0
  691.                End If
  692.  
  693.            End If
  694.  
  695.            Select Case wParam
  696.  
  697.                Case MouseMessages.WM_MOUSEMOVE
  698.                    RaiseEvent MouseMove(Me, New Point(x, y))
  699.  
  700.                Case MouseMessages.WM_LBUTTONDOWN
  701.                    RaiseEvent MouseLeftDown(Me, New Point(x, y))
  702.  
  703.                Case MouseMessages.WM_LBUTTONUP
  704.                    If LeftClickTime <> 0 Then
  705.                        LeftClickTime = Environment.TickCount() - LeftClickTime
  706.                    End If
  707.  
  708.                    If (LeftClickTime <> 0I) AndAlso (LeftClickTime < NativeMethods.GetDoubleClickTime()) Then
  709.                        LeftClickTime = 0I
  710.                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
  711.                            RaiseEvent MouseLeftUp(Me, New Point(x, y))
  712.                        End If
  713.                        RaiseEvent MouseLeftDoubleClick(Me, New Point(x, y))
  714.  
  715.                    Else
  716.                        LeftClickTime = Environment.TickCount()
  717.                        RaiseEvent MouseLeftUp(Me, New Point(x, y))
  718.  
  719.                    End If
  720.  
  721.                Case MouseMessages.WM_RBUTTONDOWN
  722.                    RaiseEvent MouseRightDown(Me, New Point(x, y))
  723.  
  724.                Case MouseMessages.WM_RBUTTONUP
  725.                    If RightClickTime <> 0I Then
  726.                        RightClickTime = Environment.TickCount() - RightClickTime
  727.                    End If
  728.  
  729.                    If (RightClickTime <> 0I) AndAlso (RightClickTime < NativeMethods.GetDoubleClickTime()) Then
  730.                        RightClickTime = 0I
  731.                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
  732.                            RaiseEvent MouseRightUp(Me, New Point(x, y))
  733.                        End If
  734.                        RaiseEvent MouseRightDoubleClick(Me, New Point(x, y))
  735.  
  736.                    Else
  737.                        RightClickTime = Environment.TickCount()
  738.                        RaiseEvent MouseRightUp(Me, New Point(x, y))
  739.  
  740.                    End If
  741.  
  742.                Case MouseMessages.WM_MBUTTONDOWN
  743.                    RaiseEvent MouseMiddleDown(Me, New Point(x, y))
  744.  
  745.                Case MouseMessages.WM_MBUTTONUP
  746.                    If MiddleClickTime <> 0I Then
  747.                        MiddleClickTime = Environment.TickCount() - MiddleClickTime
  748.                    End If
  749.  
  750.                    If (MiddleClickTime <> 0I) AndAlso (MiddleClickTime < NativeMethods.GetDoubleClickTime()) Then
  751.                        MiddleClickTime = 0I
  752.                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
  753.                            RaiseEvent MouseMiddleUp(Me, New Point(x, y))
  754.                        End If
  755.                        RaiseEvent MouseMiddleDoubleClick(Me, New Point(x, y))
  756.  
  757.                    Else
  758.                        MiddleClickTime = Environment.TickCount()
  759.                        RaiseEvent MouseMiddleUp(Me, New Point(x, y))
  760.  
  761.                    End If
  762.  
  763.                Case MouseMessages.WM_MOUSEWHEEL
  764.                    RaiseEvent MouseWheel(Me, New Point(x, y), If(MouseStruct.mouseData < 0I,
  765.                                                                 WheelDirection.WheelDown,
  766.                                                                 WheelDirection.WheelUp))
  767.  
  768.                Case Else
  769.                    Exit Select ' Do Nothing
  770.  
  771.            End Select
  772.  
  773.            Return 0I
  774.  
  775.        ElseIf nCode < 0I Then
  776.                Return NativeMethods.CallNextHookEx(MouseHook, nCode, wParam, lParam)
  777.  
  778.        Else ' nCode > 0
  779.                Return -1I
  780.  
  781.        End If
  782.  
  783.    End Function
  784.  
  785. #End Region
  786.  
  787. #Region " Hidden Methods "
  788.  
  789.    ''' <summary>
  790.    ''' Serves as a hash function for a particular type.
  791.    ''' </summary>
  792.    <EditorBrowsable(EditorBrowsableState.Never)>
  793.    Public Shadows Sub GetHashCode()
  794.    End Sub
  795.  
  796.    ''' <summary>
  797.    ''' Gets the System.Type of the current instance.
  798.    ''' </summary>
  799.    ''' <returns>The exact runtime type of the current instance.</returns>
  800.    <EditorBrowsable(EditorBrowsableState.Never)>
  801.    Public Shadows Function [GetType]()
  802.        Return Me.GetType
  803.    End Function
  804.  
  805.    ''' <summary>
  806.    ''' Determines whether the specified System.Object instances are considered equal.
  807.    ''' </summary>
  808.    <EditorBrowsable(EditorBrowsableState.Never)>
  809.    Public Shadows Sub Equals()
  810.    End Sub
  811.  
  812.    ''' <summary>
  813.    ''' Determines whether the specified System.Object instances are the same instance.
  814.    ''' </summary>
  815.    <EditorBrowsable(EditorBrowsableState.Never)>
  816.    Private Shadows Sub ReferenceEquals()
  817.    End Sub
  818.  
  819.    ''' <summary>
  820.    ''' Returns a String that represents the current object.
  821.    ''' </summary>
  822.    <EditorBrowsable(EditorBrowsableState.Never)>
  823.    Public Shadows Sub ToString()
  824.    End Sub
  825.  
  826. #End Region
  827.  
  828. #Region "IDisposable Support"
  829.  
  830.    ''' <summary>
  831.    ''' Flag to detect redundant calls at <see cref="Dispose"/> method.
  832.    ''' </summary>
  833.    Private disposedValue As Boolean
  834.  
  835.    ''' <summary>
  836.    ''' Releases unmanaged and optionally managed resources.
  837.    ''' </summary>
  838.    ''' <param name="disposing">
  839.    ''' <c>true</c> to release both managed and unmanaged resources;
  840.    ''' <c>false</c> to release only unmanaged resources.
  841.    ''' </param>
  842.    Protected Sub Dispose(ByVal disposing As Boolean)
  843.  
  844.        If Not Me.disposedValue Then
  845.  
  846.            If disposing Then ' Dispose managed state (managed objects).
  847.  
  848.            Else ' Free unmanaged resources (unmanaged objects).
  849.                NativeMethods.UnhookWindowsHookEx(Me.MouseHook)
  850.  
  851.            End If
  852.  
  853.        End If
  854.  
  855.        Me.disposedValue = True
  856.  
  857.    End Sub
  858.  
  859.    ''' <summary>
  860.    ''' Allows an object to try to free resources
  861.    ''' and perform other cleanup operations before it is reclaimed by garbage collection.
  862.    ''' </summary>
  863.    Protected Overrides Sub Finalize()
  864.  
  865.        ' Do not change this code. Put cleanup code in method: Dispose(ByVal disposing As Boolean)
  866.  
  867.        Me.Dispose(disposing:=False)
  868.        MyBase.Finalize()
  869.  
  870.    End Sub
  871.  
  872.    ''' <summary>
  873.    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  874.    ''' </summary>
  875.    Private Sub Dispose() Implements IDisposable.Dispose
  876.  
  877.        ' Do not change this code. Put cleanup code in method: Dispose(ByVal disposing As Boolean)
  878.  
  879.        Me.Dispose(disposing:=True)
  880.        GC.SuppressFinalize(obj:=Me)
  881.  
  882.    End Sub
  883.  
  884. #End Region
  885.  
  886. End Class
  887.  
  888. #End Region
6598  Programación / .NET (C#, VB.NET, ASP) / Re: [APORTE] Ejemplo de un LL-Hook para el Mouse. en: 26 Septiembre 2014, 14:32 pm
un último repaso definitivo a esta Class, para fijar un pequeño problema con las coordenadas.

Código
  1. ' ***********************************************************************
  2. ' Author           : Elektro
  3. ' Last Modified On : 09-26-2014
  4. ' ***********************************************************************
  5. ' <copyright file="MouseHook.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Instructions "
  11.  
  12. ' Go to page:
  13. ' Project > Properties > Debug
  14. '
  15. ' Then uncheck the option:
  16. ' "Enable the Visual Studio Hosting Process"
  17.  
  18. #End Region
  19.  
  20. #Region " Usage Examples "
  21.  
  22. #End Region
  23.  
  24. #Region " Imports "
  25.  
  26. Imports System.ComponentModel
  27. Imports System.Reflection
  28. Imports System.Runtime.InteropServices
  29.  
  30. #End Region
  31.  
  32. #Region " MouseHook "
  33.  
  34. ''' <summary>
  35. ''' A low level mouse hook that processes mouse input events.
  36. ''' </summary>
  37. Friend NotInheritable Class MouseHook : Implements IDisposable
  38.  
  39. #Region " P/Invoke "
  40.  
  41.    ''' <summary>
  42.    ''' Platform Invocation methods (P/Invoke), access unmanaged code.
  43.    ''' This class does not suppress stack walks for unmanaged code permission.
  44.    ''' <see cref="System.Security.SuppressUnmanagedCodeSecurityAttribute"/>  must not be applied to this class.
  45.    ''' This class is for methods that can be used anywhere because a stack walk will be performed.
  46.    ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/ms182161.aspx
  47.    ''' </summary>
  48.    Protected NotInheritable Class NativeMethods
  49.  
  50. #Region " Methods "
  51.  
  52.        ''' <summary>
  53.        ''' Passes the hook information to the next hook procedure in the current hook chain.
  54.        ''' A hook procedure can call this function either before or after processing the hook information.
  55.        ''' For more info see here:
  56.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644974%28v=vs.85%29.aspx
  57.        ''' </summary>
  58.        ''' <param name="idHook">
  59.        ''' This parameter is ignored.
  60.        ''' </param>
  61.        ''' <param name="nCode">
  62.        ''' The hook code passed to the current hook procedure.
  63.        ''' The next hook procedure uses this code to determine how to process the hook information.
  64.        ''' </param>
  65.        ''' <param name="wParam">
  66.        ''' The wParam value passed to the current hook procedure.
  67.        ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
  68.        ''' </param>
  69.        ''' <param name="lParam">
  70.        ''' The lParam value passed to the current hook procedure.
  71.        ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
  72.        ''' </param>
  73.        ''' <returns>
  74.        ''' This value is returned by the next hook procedure in the chain.
  75.        ''' The current hook procedure must also return this value.
  76.        ''' The meaning of the return value depends on the hook type.
  77.        ''' For more information, see the descriptions of the individual hook procedures.
  78.        ''' </returns>
  79.        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  80.        Friend Shared Function CallNextHookEx(
  81.               ByVal idHook As IntPtr,
  82.               ByVal nCode As Integer,
  83.               ByVal wParam As IntPtr,
  84.               ByVal lParam As IntPtr
  85.        ) As IntPtr
  86.        End Function
  87.  
  88.        ''' <summary>
  89.        ''' Installs an application-defined hook procedure into a hook chain.
  90.        ''' You would install a hook procedure to monitor the system for certain types of events.
  91.        ''' These events are associated either with a specific thread
  92.        ''' or with all threads in the same desktop as the calling thread.
  93.        ''' For more info see here:
  94.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
  95.        ''' </summary>
  96.        ''' <param name="idHook">
  97.        ''' The type of hook procedure to be installed.
  98.        ''' </param>
  99.        ''' <param name="lpfn">
  100.        ''' A pointer to the hook procedure.
  101.        ''' If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process,
  102.        ''' the lpfn parameter must point to a hook procedure in a DLL.
  103.        ''' Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
  104.        ''' </param>
  105.        ''' <param name="hInstance">
  106.        ''' A handle to the DLL containing the hook procedure pointed to by the lpfn parameter.
  107.        ''' The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by
  108.        ''' the current process and if the hook procedure is within the code associated with the current process.
  109.        ''' </param>
  110.        ''' <param name="threadId">
  111.        ''' The identifier of the thread with which the hook procedure is to be associated.
  112.        ''' For desktop apps, if this parameter is zero, the hook procedure is associated
  113.        ''' with all existing threads running in the same desktop as the calling thread.
  114.        ''' </param>
  115.        ''' <returns>
  116.        ''' If the function succeeds, the return value is the handle to the hook procedure.
  117.        ''' If the function fails, the return value is NULL.
  118.        ''' </returns>
  119.        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  120.        Friend Shared Function SetWindowsHookEx(
  121.               ByVal idHook As HookType,
  122.               ByVal lpfn As LowLevelMouseProcDelegate,
  123.               ByVal hInstance As IntPtr,
  124.               ByVal threadId As UInteger
  125.        ) As IntPtr
  126.        End Function
  127.  
  128.        ''' <summary>
  129.        ''' Removes a hook procedure installed in a hook chain by the 'SetWindowsHookEx' function.
  130.        ''' For more info see here:
  131.        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644993%28v=vs.85%29.aspx
  132.        ''' </summary>
  133.        ''' <param name="idHook">
  134.        ''' A handle to the hook to be removed.
  135.        ''' This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
  136.        ''' </param>
  137.        ''' <returns>
  138.        ''' If the function succeeds, the return value is nonzero.
  139.        ''' If the function fails, the return value is zero.
  140.        ''' </returns>
  141.        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
  142.        Friend Shared Function UnhookWindowsHookEx(
  143.               ByVal idHook As IntPtr
  144.        ) As Boolean
  145.        End Function
  146.  
  147.        ''' <summary>
  148.        ''' Retrieves the current double-click time for the mouse.
  149.        ''' A double-click is a series of two clicks of the mouse button,
  150.        ''' the second occurring within a specified time after the first.
  151.        ''' The double-click time is the maximum number of milliseconds that may occur
  152.        ''' between the first and second click of a double-click.
  153.        ''' The maximum double-click time is 5000 milliseconds.
  154.        ''' </summary>
  155.        ''' <returns>
  156.        ''' The return value specifies the current double-click time, in milliseconds.
  157.        ''' The maximum return value is 5000 milliseconds.
  158.        ''' </returns>
  159.        <DllImport("user32.dll", CharSet:=CharSet.Auto)>
  160.        Friend Shared Function GetDoubleClickTime() As Integer
  161.        End Function
  162.  
  163. #End Region
  164.  
  165. #Region " Enumerations "
  166.  
  167.        ''' <summary>
  168.        ''' Indicates a type of Hook procedure to be installed.
  169.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
  170.        ''' </summary>
  171.        <Description("Enum used in 'idHook' parameter of 'SetWindowsHookEx' function.")>
  172.        Friend Enum HookType As UInteger
  173.  
  174.            ' **************************************
  175.            ' This enumeration is partially defined.
  176.            ' **************************************
  177.  
  178.            ''' <summary>
  179.            ''' Installs a hook procedure that monitors low-level mouse input events.
  180.            ''' For more information, see the LowLevelMouseProc hook procedure.
  181.            ''' </summary>
  182.            WH_MOUSE_LL = 14UI
  183.  
  184.        End Enum
  185.  
  186.        ''' <summary>
  187.        ''' The event-injected flags.
  188.        ''' An application can use the following values to test the flags.
  189.        ''' Testing LLMHF_INJECTED (bit 0) will tell you whether the event was injected.
  190.        ''' If it was, then testing LLMHF_LOWER_IL_INJECTED (bit 1) will tell you
  191.        ''' whether or not the event was injected from a process running at lower integrity level.
  192.        ''' </summary>
  193.        <Flags()>
  194.        <Description("Enum used in 'flags' parameter of 'MSLLHOOKSTRUCT' structure.")>
  195.        Public Enum MSLLHOOKSTRUCTFlags As Integer
  196.  
  197.            ''' <summary>
  198.            ''' Test the event-injected (from any process) flag.
  199.            ''' </summary>
  200.            LLMHF_INJECTED = 1
  201.  
  202.            ''' <summary>
  203.            ''' Test the event-injected (from a process running at lower integrity level) flag.
  204.            ''' </summary>
  205.            LLMHF_LOWER_IL_INJECTED = 2
  206.  
  207.        End Enum
  208.  
  209. #End Region
  210.  
  211. #Region " Structures "
  212.  
  213.        ''' <summary>
  214.        ''' The POINT structure defines the x- and y- coordinates of a point.
  215.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162805%28v=vs.85%29.aspx
  216.        ''' </summary>
  217.        <Description("Structure used in 'pt' parameter of 'MSLLHOOKSTRUCT' structure.")>
  218.        <StructLayout(LayoutKind.Sequential)>
  219.        Friend Structure POINT
  220.  
  221.            ''' <summary>
  222.            ''' The x-coordinate of the point.
  223.            ''' </summary>
  224.            Public X As Integer
  225.  
  226.            ''' <summary>
  227.            ''' The y-coordinate of the point.
  228.            ''' </summary>
  229.            Public Y As Integer
  230.  
  231.        End Structure
  232.  
  233.        ''' <summary>
  234.        ''' Contains information about a low-level mouse input event.
  235.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644970%28v=vs.85%29.aspx
  236.        ''' </summary>
  237.        <Description("Structure used in 'lParam' parameter of 'CallNextHookEx' function.")>
  238.        Friend Structure MSLLHOOKSTRUCT
  239.  
  240.            ''' <summary>
  241.            ''' The ptThe x- and y-coordinates of the cursor, in screen coordinates.
  242.            ''' </summary>
  243.            Friend pt As NativeMethods.POINT
  244.  
  245.            ''' <summary>
  246.            ''' If the message is 'WM_MOUSEWHEEL', the high-order word of this member is the wheel delta.
  247.            ''' The low-order word is reserved.
  248.            ''' A positive value indicates that the wheel was rotated forward, away from the user;
  249.            ''' a negative value indicates that the wheel was rotated backward, toward the user.
  250.            ''' One wheel click is defined as 'WHEEL_DELTA', which is '120'.
  251.            ''' </summary>
  252.            Friend mouseData As Integer
  253.  
  254.            ''' <summary>
  255.            ''' The event-injected flag.
  256.            ''' </summary>
  257.            Friend flags As MSLLHOOKSTRUCTFlags
  258.  
  259.            ''' <summary>
  260.            ''' The time stamp for this message.
  261.            ''' </summary>
  262.            Friend time As UInteger
  263.  
  264.            ''' <summary>
  265.            ''' Additional information associated with the message.
  266.            ''' </summary>
  267.            Friend dwExtraInfo As IntPtr
  268.  
  269.        End Structure
  270.  
  271. #End Region
  272.  
  273. #Region " Delegates "
  274.  
  275.        ''' <summary>
  276.        ''' Delegate LowLevelMouseProc
  277.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx
  278.        ''' </summary>
  279.        ''' <returns>
  280.        ''' If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
  281.        ''' If nCode is greater than or equal to zero, and the hook procedure did not process the message,
  282.        ''' it is highly recommended that you call CallNextHookEx and return the value it returns;
  283.        ''' otherwise, other applications that have installed WH_MOUSE_LL hooks will not receive hook notifications
  284.        ''' and may behave incorrectly as a result.
  285.        ''' If the hook procedure processed the message,
  286.        ''' it may return a nonzero value to prevent the system from passing the message to the rest of the hook chain or the target window procedure.
  287.        ''' </returns>
  288.        Friend Delegate Function LowLevelMouseProcDelegate(
  289.                ByVal nCode As IntPtr,
  290.                ByVal wParam As IntPtr,
  291.                ByVal lParam As IntPtr
  292.        ) As Integer
  293.  
  294. #End Region
  295.  
  296. #Region " Hidden Methods "
  297.  
  298.        ''' <summary>
  299.        ''' Determines whether the specified System.Object instances are considered equal.
  300.        ''' </summary>
  301.        <EditorBrowsable(EditorBrowsableState.Never)>
  302.        Public Shadows Sub Equals()
  303.        End Sub
  304.  
  305.        ''' <summary>
  306.        ''' Determines whether the specified System.Object instances are the same instance.
  307.        ''' </summary>
  308.        <EditorBrowsable(EditorBrowsableState.Never)>
  309.        Private Shadows Sub ReferenceEquals()
  310.        End Sub
  311.  
  312. #End Region
  313.  
  314.    End Class
  315.  
  316. #End Region
  317.  
  318. #Region " Objects "
  319.  
  320.    ''' <summary>
  321.    ''' Handle to the hook procedure.
  322.    ''' </summary>
  323.    Private MouseHook As IntPtr
  324.  
  325.    ''' <summary>
  326.    ''' The mouse hook delegate.
  327.    ''' </summary>
  328.    Private MouseHookDelegate As NativeMethods.LowLevelMouseProcDelegate
  329.  
  330. #End Region
  331.  
  332. #Region " Properties "
  333.  
  334.    ''' <summary>
  335.    ''' ** ONLY FOR TESTING PURPOSES **
  336.    ''' Gets or sets a value indicating whether to suppress the last MouseUp event of
  337.    ''' the specified clicked button when a double-click fires.
  338.    '''
  339.    ''' If this value is set to <c>true</c>, the application will send the events in this order for a Double-Click:
  340.    ''' MouseDown, MouseUp, MouseDown, MouseDoubleClick
  341.    '''
  342.    ''' If this value is set to <c>false</c>, the application will send the events in this order for a Double-Click:
  343.    ''' MouseDown, MouseUp, MouseDown, MouseUp, MouseDoubleClick
  344.    '''
  345.    ''' </summary>
  346.    ''' <value><c>true</c> if MouseUp event is suppressed; otherwise <c>false</c>.</value>
  347.    Friend Property SuppressMouseUpEventWhenDoubleClick As Boolean = False
  348.  
  349. #End Region
  350.  
  351. #Region " Enumerations "
  352.  
  353.    ''' <summary>
  354.    ''' Indicates a Windows Message related to a mouse events.
  355.    ''' For more info see here:
  356.    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ff468877%28v=vs.85%29.aspx
  357.    ''' </summary>
  358.    Private Enum MouseMessages As UInteger
  359.  
  360.        ''' <summary>
  361.        ''' Posted to a window when the cursor moves.
  362.        ''' If the mouse is not captured, the message is posted to the window that contains the cursor.
  363.        ''' Otherwise, the message is posted to the window that has captured the mouse
  364.        ''' </summary>
  365.        WM_MOUSEMOVE = &H200UI
  366.  
  367.        ''' <summary>
  368.        ''' Posted when the user presses the left mouse button while the cursor is in the client area of a window.
  369.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  370.        ''' Otherwise, the message is posted to the window that has captured the mouse
  371.        ''' </summary>
  372.        WM_LBUTTONDOWN = &H201UI
  373.  
  374.        ''' <summary>
  375.        ''' Posted when the user releases the left mouse button while the cursor is in the client area of a window.
  376.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  377.        ''' Otherwise, the message is posted to the window that has captured the mouse
  378.        ''' </summary>
  379.        WM_LBUTTONUP = &H202UI
  380.  
  381.        ''' <summary>
  382.        ''' Posted when the user presses the right mouse button while the cursor is in the client area of a window.
  383.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  384.        ''' Otherwise, the message is posted to the window that has captured the mouse
  385.        ''' </summary>
  386.        WM_RBUTTONDOWN = &H204UI
  387.  
  388.        ''' <summary>
  389.        ''' Posted when the user releases the right mouse button while the cursor is in the client area of a window.
  390.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  391.        ''' Otherwise, the message is posted to the window that has captured the mouse
  392.        ''' </summary>
  393.        WM_RBUTTONUP = &H205UI
  394.  
  395.        ''' <summary>
  396.        ''' Posted when the user presses the middle mouse button while the cursor is in the client area of a window.
  397.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  398.        ''' Otherwise, the message is posted to the window that has captured the mouse
  399.        ''' </summary>
  400.        WM_MBUTTONDOWN = &H207UI
  401.  
  402.        ''' <summary>
  403.        ''' Posted when the user releases the middle mouse button while the cursor is in the client area of a window.
  404.        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
  405.        ''' Otherwise, the message is posted to the window that has captured the mouse
  406.        ''' </summary>
  407.        WM_MBUTTONUP = &H208UI
  408.  
  409.        ''' <summary>
  410.        ''' Sent to the active window when the mouse's horizontal scroll wheel is tilted or rotated.
  411.        ''' The DefWindowProc function propagates the message to the window's parent.
  412.        ''' There should be no internal forwarding of the message,
  413.        ''' since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
  414.        ''' </summary>
  415.        WM_MOUSEWHEEL = &H20AUI
  416.  
  417.    End Enum
  418.  
  419.    ''' <summary>
  420.    ''' Indicates the whell direction of the mouse.
  421.    ''' </summary>
  422.    Public Enum WheelDirection As Integer
  423.  
  424.        ''' <summary>
  425.        ''' The wheel is moved up.
  426.        ''' </summary>
  427.        WheelUp = 1
  428.  
  429.        ''' <summary>
  430.        ''' The wheel is moved down.
  431.        ''' </summary>
  432.        WheelDown = 2
  433.  
  434.    End Enum
  435.  
  436. #End Region
  437.  
  438. #Region " Events "
  439.  
  440.    ''' <summary>
  441.    ''' Occurs when the mouse moves.
  442.    ''' </summary>
  443.    Friend Event MouseMove(ByVal sender As Object,
  444.                           ByVal MouseLocation As Point)
  445.  
  446.    ''' <summary>
  447.    ''' Occurs when the mouse left button is pressed.
  448.    ''' </summary>
  449.    Friend Event MouseLeftDown(ByVal sender As Object,
  450.                               ByVal MouseLocation As Point)
  451.  
  452.    ''' <summary>
  453.    ''' Occurs when the mouse left button is released.
  454.    ''' </summary>
  455.    Friend Event MouseLeftUp(ByVal sender As Object,
  456.                             ByVal MouseLocation As Point)
  457.  
  458.    ''' <summary>
  459.    ''' Occurs when the mouse left button performs a double-click.
  460.    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
  461.    ''' </summary>
  462.    Friend Event MouseLeftDoubleClick(ByVal sender As Object,
  463.                                      ByVal MouseLocation As Point)
  464.  
  465.    ''' <summary>
  466.    ''' Occurs when the mouse right button is pressed.
  467.    ''' </summary>
  468.    Friend Event MouseRightDown(ByVal sender As Object,
  469.                                ByVal MouseLocation As Point)
  470.  
  471.    ''' <summary>
  472.    ''' Occurs when the mouse right button is released.
  473.    ''' </summary>
  474.    Friend Event MouseRightUp(ByVal sender As Object,
  475.                              ByVal MouseLocation As Point)
  476.  
  477.    ''' <summary>
  478.    ''' Occurs when the mouse right button performs a double-click.
  479.    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
  480.    ''' </summary>
  481.    Friend Event MouseRightDoubleClick(ByVal sender As Object,
  482.                                       ByVal MouseLocation As Point)
  483.  
  484.    ''' <summary>
  485.    ''' Occurs when the mouse middle button is pressed.
  486.    ''' </summary>
  487.    Friend Event MouseMiddleDown(ByVal sender As Object,
  488.                                 ByVal MouseLocation As Point)
  489.  
  490.    ''' <summary>
  491.    ''' Occurs when the mouse middle button is released.
  492.    ''' </summary>
  493.    Friend Event MouseMiddleUp(ByVal sender As Object,
  494.                               ByVal MouseLocation As Point)
  495.  
  496.    ''' <summary>
  497.    ''' Occurs when the mouse middle button performs a double-click.
  498.    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
  499.    ''' </summary>
  500.    Friend Event MouseMiddleDoubleClick(ByVal sender As Object,
  501.                                        ByVal MouseLocation As Point)
  502.  
  503.    ''' <summary>
  504.    ''' Occurs when the mouse wheel is moved up or down.
  505.    ''' </summary>
  506.    Friend Event MouseWheel(ByVal sender As Object,
  507.                            ByVal MouseLocation As Point,
  508.                            ByVal WheelDirection As WheelDirection)
  509.  
  510. #End Region
  511.  
  512. #Region " Constructors "
  513.  
  514.    ''' <summary>
  515.    ''' Prevents a default instance of the <see cref="MouseHook"/> class from being created.
  516.    ''' </summary>
  517.    Private Sub New()
  518.    End Sub
  519.  
  520.    ''' <summary>
  521.    ''' Initializes a new instance of the <see cref="MouseHook"/> class.
  522.    ''' </summary>
  523.    ''' <param name="Install">
  524.    ''' If set to <c>true</c>, the Hook starts initialized for this <see cref="MouseHook"/> instance.
  525.    ''' </param>
  526.    Friend Sub New(Optional ByVal Install As Boolean = False)
  527.  
  528.        If Install Then
  529.            Me.Install()
  530.        End If
  531.  
  532.    End Sub
  533.  
  534. #End Region
  535.  
  536. #Region " Public Methods "
  537.  
  538.    ''' <summary>
  539.    ''' Installs the Mouse Hook, then start processing messages to fire events.
  540.    ''' </summary>
  541.    Friend Sub Install()
  542.  
  543.        Me.MouseHookDelegate = New NativeMethods.LowLevelMouseProcDelegate(AddressOf LowLevelMouseProc)
  544.  
  545.        Try
  546.            Me.MouseHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL,
  547.                                                          Me.MouseHookDelegate,
  548.                                                          Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
  549.  
  550.        Catch ex As Exception
  551.            Throw
  552.  
  553.        End Try
  554.  
  555.    End Sub
  556.  
  557.    ''' <summary>
  558.    ''' Uninstalls the Mouse Hook and free all resources, then stop processing messages to fire events.
  559.    ''' </summary>
  560.    Friend Sub Uninstall()
  561.  
  562.        Me.Finalize()
  563.  
  564.    End Sub
  565.  
  566. #End Region
  567.  
  568. #Region " Private Methods "
  569.  
  570.    ''' <summary>
  571.    ''' Processes the mouse windows messages and raises it's corresponding events.
  572.    ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx
  573.    ''' </summary>
  574.    ''' <param name="nCode">
  575.    ''' A code the hook procedure uses to determine how to process the message.
  576.    ''' If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function
  577.    ''' without further processing and should return the value returned by CallNextHookEx.
  578.    ''' </param>
  579.    ''' <param name="wParam">The identifier of the mouse message.</param>
  580.    ''' <param name="lParam"> A pointer to an <see cref="NativeMethods.MSLLHOOKSTRUCT"/> structure.</param>
  581.    ''' <returns>
  582.    ''' If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
  583.    ''' If nCode is greater than or equal to zero, and the hook procedure did not process the message,
  584.    ''' it is highly recommended that you call CallNextHookEx and return the value it returns;
  585.    ''' otherwise, other applications that have installed WH_MOUSE_LL hooks will not receive hook notifications
  586.    ''' and may behave incorrectly as a result.
  587.    ''' If the hook procedure processed the message,
  588.    ''' it may return a nonzero value to prevent the system from passing the
  589.    ''' message to the rest of the hook chain or the target window procedure.
  590.    ''' </returns>
  591.    Private Function LowLevelMouseProc(ByVal nCode As Integer,
  592.                                       ByVal wParam As MouseMessages,
  593.                                       ByVal lParam As IntPtr) As Integer
  594.  
  595.        Static LeftClickTime As Integer = 0I ' Determines a left button double-click.
  596.        Static RightClickTime As Integer = 0I ' Determines a right button double-click.
  597.        Static MiddleClickTime As Integer = 0I ' Determines a middle button double-click.
  598.  
  599.        If nCode = 0I Then
  600.  
  601.            Dim x As Integer
  602.            Dim y As Integer
  603.  
  604.            Dim MouseStruct As NativeMethods.MSLLHOOKSTRUCT
  605.            MouseStruct = CType(Marshal.PtrToStructure(lParam, MouseStruct.GetType()),
  606.                                NativeMethods.MSLLHOOKSTRUCT)
  607.  
  608.            ' Fix X coordinate.
  609.            Select Case MouseStruct.pt.X
  610.  
  611.                Case Is < 0I
  612.                    x = 0I
  613.  
  614.                Case Is > SystemInformation.VirtualScreen.Width
  615.                    x = SystemInformation.VirtualScreen.Width
  616.  
  617.                Case Else
  618.                    x = MouseStruct.pt.X
  619.  
  620.            End Select
  621.  
  622.            ' Fix Y coordinate.
  623.            Select Case MouseStruct.pt.Y
  624.  
  625.                Case Is > SystemInformation.VirtualScreen.Height
  626.                    y = SystemInformation.VirtualScreen.Height
  627.  
  628.                Case Is < 0I
  629.                    y = 0I
  630.  
  631.                Case Else
  632.                    y = MouseStruct.pt.Y
  633.  
  634.            End Select
  635.  
  636.            Select Case wParam
  637.  
  638.                Case MouseMessages.WM_MOUSEMOVE
  639.                    RaiseEvent MouseMove(Me, New Point(x, y))
  640.  
  641.                Case MouseMessages.WM_LBUTTONDOWN
  642.                    RaiseEvent MouseLeftDown(Me, New Point(x, y))
  643.  
  644.                Case MouseMessages.WM_LBUTTONUP
  645.                    If LeftClickTime <> 0 Then
  646.                        LeftClickTime = Environment.TickCount() - LeftClickTime
  647.                    End If
  648.  
  649.                    If (LeftClickTime <> 0) AndAlso (LeftClickTime < NativeMethods.GetDoubleClickTime()) Then
  650.                        LeftClickTime = 0
  651.                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
  652.                            RaiseEvent MouseLeftUp(Me, New Point(x, y))
  653.                        End If
  654.                        RaiseEvent MouseLeftDoubleClick(Me, New Point(x, y))
  655.  
  656.                    Else
  657.                        LeftClickTime = Environment.TickCount()
  658.                        RaiseEvent MouseLeftUp(Me, New Point(x, y))
  659.  
  660.                    End If
  661.  
  662.                Case MouseMessages.WM_RBUTTONDOWN
  663.                    RaiseEvent MouseRightDown(Me, New Point(x, y))
  664.  
  665.                Case MouseMessages.WM_RBUTTONUP
  666.                    If RightClickTime <> 0 Then
  667.                        RightClickTime = Environment.TickCount() - RightClickTime
  668.                    End If
  669.  
  670.                    If (RightClickTime <> 0) AndAlso (RightClickTime < NativeMethods.GetDoubleClickTime()) Then
  671.                        RightClickTime = 0
  672.                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
  673.                            RaiseEvent MouseRightUp(Me, New Point(x, y))
  674.                        End If
  675.                        RaiseEvent MouseRightDoubleClick(Me, New Point(x, y))
  676.  
  677.                    Else
  678.                        RightClickTime = Environment.TickCount()
  679.                        RaiseEvent MouseRightUp(Me, New Point(x, y))
  680.  
  681.                    End If
  682.  
  683.                Case MouseMessages.WM_MBUTTONDOWN
  684.                    RaiseEvent MouseMiddleDown(Me, New Point(x, y))
  685.  
  686.                Case MouseMessages.WM_MBUTTONUP
  687.                    If MiddleClickTime <> 0 Then
  688.                        MiddleClickTime = Environment.TickCount() - MiddleClickTime
  689.                    End If
  690.  
  691.                    If (MiddleClickTime <> 0) AndAlso (MiddleClickTime < NativeMethods.GetDoubleClickTime()) Then
  692.                        MiddleClickTime = 0
  693.                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
  694.                            RaiseEvent MouseMiddleUp(Me, New Point(x, y))
  695.                        End If
  696.                        RaiseEvent MouseMiddleDoubleClick(Me, New Point(x, y))
  697.  
  698.                    Else
  699.                        MiddleClickTime = Environment.TickCount()
  700.                        RaiseEvent MouseMiddleUp(Me, New Point(x, y))
  701.  
  702.                    End If
  703.  
  704.                Case MouseMessages.WM_MOUSEWHEEL
  705.                    RaiseEvent MouseWheel(Me, New Point(x, y), If(MouseStruct.mouseData < 0,
  706.                                                                 WheelDirection.WheelDown,
  707.                                                                 WheelDirection.WheelUp))
  708.  
  709.                Case Else
  710.                    Exit Select ' Do Nothing
  711.  
  712.            End Select
  713.  
  714.            Return 0
  715.  
  716.        ElseIf nCode < 0I Then
  717.            Return NativeMethods.CallNextHookEx(MouseHook, nCode, wParam, lParam)
  718.  
  719.        Else ' nCode > 0
  720.            Return -1I
  721.  
  722.        End If
  723.  
  724.    End Function
  725.  
  726. #End Region
  727.  
  728. #Region " Hidden Methods "
  729.  
  730.    ''' <summary>
  731.    ''' Serves as a hash function for a particular type.
  732.    ''' </summary>
  733.    <EditorBrowsable(EditorBrowsableState.Never)>
  734.    Public Shadows Sub GetHashCode()
  735.    End Sub
  736.  
  737.    ''' <summary>
  738.    ''' Gets the System.Type of the current instance.
  739.    ''' </summary>
  740.    ''' <returns>The exact runtime type of the current instance.</returns>
  741.    <EditorBrowsable(EditorBrowsableState.Never)>
  742.    Public Shadows Function [GetType]()
  743.        Return Me.GetType
  744.    End Function
  745.  
  746.    ''' <summary>
  747.    ''' Determines whether the specified System.Object instances are considered equal.
  748.    ''' </summary>
  749.    <EditorBrowsable(EditorBrowsableState.Never)>
  750.    Public Shadows Sub Equals()
  751.    End Sub
  752.  
  753.    ''' <summary>
  754.    ''' Determines whether the specified System.Object instances are the same instance.
  755.    ''' </summary>
  756.    <EditorBrowsable(EditorBrowsableState.Never)>
  757.    Private Shadows Sub ReferenceEquals()
  758.    End Sub
  759.  
  760.    ''' <summary>
  761.    ''' Returns a String that represents the current object.
  762.    ''' </summary>
  763.    <EditorBrowsable(EditorBrowsableState.Never)>
  764.    Public Shadows Sub ToString()
  765.    End Sub
  766.  
  767. #End Region
  768.  
  769. #Region "IDisposable Support"
  770.  
  771.    ''' <summary>
  772.    ''' Flag to detect redundant calls at <see cref="Dispose"/> method.
  773.    ''' </summary>
  774.    Private disposedValue As Boolean
  775.  
  776.    ''' <summary>
  777.    ''' Releases unmanaged and optionally managed resources.
  778.    ''' </summary>
  779.    ''' <param name="disposing">
  780.    ''' <c>true</c> to release both managed and unmanaged resources;
  781.    ''' <c>false</c> to release only unmanaged resources.
  782.    ''' </param>
  783.    Protected Sub Dispose(ByVal disposing As Boolean)
  784.  
  785.        If Not Me.disposedValue Then
  786.  
  787.            If disposing Then ' Dispose managed state (managed objects).
  788.  
  789.            Else ' Free unmanaged resources (unmanaged objects).
  790.                NativeMethods.UnhookWindowsHookEx(Me.MouseHook)
  791.  
  792.            End If
  793.  
  794.        End If
  795.  
  796.        Me.disposedValue = True
  797.  
  798.    End Sub
  799.  
  800.    ''' <summary>
  801.    ''' Allows an object to try to free resources
  802.    ''' and perform other cleanup operations before it is reclaimed by garbage collection.
  803.    ''' </summary>
  804.    Protected Overrides Sub Finalize()
  805.  
  806.        ' Do not change this code. Put cleanup code in method: Dispose(ByVal disposing As Boolean)
  807.  
  808.        Me.Dispose(disposing:=False)
  809.        MyBase.Finalize()
  810.  
  811.    End Sub
  812.  
  813.    ''' <summary>
  814.    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  815.    ''' </summary>
  816.    Private Sub Dispose() Implements IDisposable.Dispose
  817.  
  818.        ' Do not change this code. Put cleanup code in method: Dispose(ByVal disposing As Boolean)
  819.  
  820.        Me.Dispose(disposing:=True)
  821.        GC.SuppressFinalize(obj:=Me)
  822.  
  823.    End Sub
  824.  
  825. #End Region
  826.  
  827. End Class
  828.  
  829. #End Region
6599  Programación / Programación General / Re: [EHN-Dev 2014] - Hilo de discusión / comentarios / dudas en: 26 Septiembre 2014, 02:23 am
¿No se podra cambiar la gorra por una sudadera? Vamos, no es tanta plata para ser un premio anual, para un solo competidor..  :silbar:

El administrador de la página (el-brujo) es quien decide los premios, y los premios ya los decidió.

Los premios ya se han publicado en el concurso y en twitter, sería una falta de respeto modificar los premios de pronto y solamente por que tu prefieres que lo cambiemos por otro premio que se adapte a tu gusto, como comprenderás eso NO puede suceder (a menos que el-brujo diga lo contrario) :P.

Por otro lado, si quedases en la 1ª posición del concurso eres libre de debatir este asunto con el responsable de llevar la gestión de la entrega de premios (que no se si será el-brujo u otra persona la que se encargue de ello), pero hasta entonces ya conoces la respuesta.

Un saludo!
6600  Programación / Scripting / Re: Analizar Ejecutable En Red? en: 26 Septiembre 2014, 02:08 am
Y para rematar, alguien sabe si existe alguna forma de correr el AV sin tenerlo activo todo el tiempo? O sea, que este instalado (o no, de ser posible) y hacer un análisis puntual y volver a cerrarse.. y todo esto sin UI, que el usuario no vea nada del proceso.

Existe cierta herramienta alojada en una página que no nombraré porque no se si es una página amiga de elhacker.net, pero ya te digo que son algo 'indetectables' ;), es un multi-scanner con una GUI que como su nombre indica recopila muchos AntiVirus portables para realizar un multi-escaneo, y ahí puedes ver en la configuración de la aplicación las instrucciones que utilizan para llamar a cada antivirus por linea de comandos para realizar el escaneo, y entonces eso sería todo lo que necesitas saber, por no decir que de ahí mismo puedes obtener varios AV portables.

Aquí tienes un enlace externo fuera de esa página: https://code.google.com/p/kims/
( aunque sinceramente, no se si la herramienta seguirá en desarrollo, hace un par de años la última vez que la utilicé  )

Prueba la aplicación bajo tu única responsabilidad, por experiencia sé que los engreidos y colaboradores de esa página que no he mencionado, no son nada de fiar.

Como esa herramienta multi AV scanner conocia otra (y más profesional), cuyo nombre no recuerdo ahora mismo :-/ pero hace unos años también...

En fin, cualquier AV se puede portabilizar después de haberlo instalado con unos mínimos conocimientos, monitorizando las claves de registro que instala, replicando los servicios que instala (en caso de ser necesarios para el funcionamiento del AV) y los archivos que éste expande (a veces llega a ser un proceso tedioso), y cualquier buen AV tiene su versión CLI (Command-Line-Interface) y eso significa que puedes realizar un escaneo de forma 'invisible'.

Por otro lado, en mi opinión creo que para realizar un multi-escaneo lo mejor sería depender de algún servicio online como VirusTotal que estuviese implementado en alguna aplicación como esta: http://securityxploded.com/virus-total-scanner.php, pero commandline, claro... no me viene a la cabeza ninguna aplicación con esa característica ahora mismo (y en el futuro, lo dudo xD).

PD: Espero que la información te haya podido servir de algo.

Saludos.
Páginas: 1 ... 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 [660] 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 ... 1236
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines