Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - Eleкtro

#6451
JJAJAJAJJAJAJAJAJA

¡ Cojonuda idea !

#6452
Puedes utilizar el módulo Datetime:

Código (python) [Seleccionar]
import datetime, locale

locale.setlocale(locale.LC_ALL, 'Spanish_Spain.1252')

print datetime.datetime.strptime('28-09-2014', '%d-%m-%Y').strftime('El dia es: %A')


Fecha '28-09-2014', día:



8.1.7. strftime() and strptime() Behavior

Saludos.
#6454
Cita de: Zzz01Breikoft en 27 Septiembre 2014, 04:10 AMcreí 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 (DOS) [Seleccionar]
@ECHO OFF & (CHCP 1252)1>NUL

:: Enumeración 'DriveType' de la Class 'Win32_LogicalDisk' de la Interface WMI.
:: Documentación: http://msdn.microsoft.com/en-us/library/aa394173%28v=vs.85%29.aspx
Set /A "HardDisk=3"
Set /A "RemovableDisk=2"

:: Cambio el directorio de trabajo actual.
PUSHD "%SystemRoot%\System32"

:: Ejecuto una Query al comando externo WMIC.exe y filtro la salida resultante.
For /F "Delims= " %%# In (
  '.\WBEM\WMIC.exe "logicaldisk" "get" "caption"^,"drivetype" ^| .\FindStr.exe "%HardDisk% %RemovableDisk%"'
) Do (
  :: Obtengo las letras de los dispositivos conectados.
  Call Set "DRIVES=%%DRIVES%%%%#"
)

:: Simple Debug.
REM Echo [Debug] Unidades encontradas: %DRIVES%

:: Elimino la letra de unidad desde la que se inició este Script;
:: ya que la letra de la unidad activa (del SO) no se podrá modificar.
:: Doy por hecho que se ejecutó desde la unidad activa del SO, de lo contrario esto necesita un retoque.
Call Set "DRIVES=%%DRIVES:%~d0=%%"

:: Reemplazo el caracter ":" del resto de letras por un caracter de "espacio";
:: de esta manera puedo usar el delimitador por defecto ("espacio") en un For.
Set "DRIVES=%DRIVES::= %"

:: Por último, proceso cada letra de unidad para crear variables de manera dinámica.
Set "INPUT="
Set /A "Count=0"

For %%D in (%DRIVES%) Do (

  Set /A "Count+=1"             & REM Incremento el contador.
  Call Set "_%%Count%%=%%D"     & REM Seteo la variable con el número del contador.
  Call Set "INPUT=%%INPUT%%%%D" & REM Asigno la letra de unidad a la variable.

)

:: Pregunto al usuario por una letra de unidad.
".\Choice.exe" /C "%INPUT%" /M "Elige una letra de unidad"
Set /A "CHOICE=%ErrorLevel%"   & REM Guardo el resultado.
Call Set "DRIVE=%%_%CHOICE%%%" & REM Seteo la letra de unidad elegida.

:: Y manejo la unidad de la forma que se desee:
Echo.
Call Echo Listado de carpetas: de la unidad "%DRIVE%:\" | .\More.com
Dir /B /AD "%DRIVE%:\*"

:: Vuelvo al directorio de trabajo inicial.
POPD

Pause&Exit /B 0


Saludos
#6455
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)





Cita de: Zzz01Breikoft en 27 Septiembre 2014, 03:36 AMya 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!
#6457
Cita de: erest0r en 27 Septiembre 2014, 02:20 AMUna 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)

Cita de: http://en.wikipedia.org/wiki/Open_sourceIn 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!
#6458
Scripting / Re: Analizar Ejecutable En Red?
26 Septiembre 2014, 22:30 PM
Cita de: Vaagish en 26 Septiembre 2014, 20:20 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!
#6459
@erest0r

Por segunda vez:

Cita de: Eleкtro en 25 Septiembre 2014, 15:49 PM
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!
#6460
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 (vbnet) [Seleccionar]
' ***********************************************************************
' Author           : Elektro
' Last Modified On : 09-26-2014
' ***********************************************************************
' <copyright file="MouseHook.vb" company="Elektro Studios">
'     Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************

#Region " Instructions "

' Go to page:
' Project > Properties > Debug
'
' Then uncheck the option:
' "Enable the Visual Studio Hosting Process"

#End Region

#Region " Usage Examples "

#End Region

#Region " Imports "

Imports System.ComponentModel
Imports System.Reflection
Imports System.Runtime.InteropServices

#End Region

#Region " MouseHook "

''' <summary>
''' A low level mouse hook that processes mouse input events.
''' </summary>
Friend NotInheritable Class MouseHook : Implements IDisposable

#Region " P/Invoke "

    ''' <summary>
    ''' Platform Invocation methods (P/Invoke), access unmanaged code.
    ''' This class does not suppress stack walks for unmanaged code permission.
    ''' <see cref="System.Security.SuppressUnmanagedCodeSecurityAttribute"/>  must not be applied to this class.
    ''' This class is for methods that can be used anywhere because a stack walk will be performed.
    ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/ms182161.aspx
    ''' </summary>
    Protected NotInheritable Class NativeMethods

#Region " Methods "

        ''' <summary>
        ''' Passes the hook information to the next hook procedure in the current hook chain.
        ''' A hook procedure can call this function either before or after processing the hook information.
        ''' For more info see here:
        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644974%28v=vs.85%29.aspx
        ''' </summary>
        ''' <param name="idHook">
        ''' This parameter is ignored.
        ''' </param>
        ''' <param name="nCode">
        ''' The hook code passed to the current hook procedure.
        ''' The next hook procedure uses this code to determine how to process the hook information.
        ''' </param>
        ''' <param name="wParam">
        ''' The wParam value passed to the current hook procedure.
        ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
        ''' </param>
        ''' <param name="lParam">
        ''' The lParam value passed to the current hook procedure.
        ''' The meaning of this parameter depends on the type of hook associated with the current hook chain.
        ''' </param>
        ''' <returns>
        ''' This value is returned by the next hook procedure in the chain.
        ''' The current hook procedure must also return this value.
        ''' The meaning of the return value depends on the hook type.
        ''' For more information, see the descriptions of the individual hook procedures.
        ''' </returns>
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
        Friend Shared Function CallNextHookEx(
               ByVal idHook As IntPtr,
               ByVal nCode As Integer,
               ByVal wParam As IntPtr,
               ByVal lParam As IntPtr
        ) As IntPtr
        End Function

        ''' <summary>
        ''' Installs an application-defined hook procedure into a hook chain.
        ''' You would install a hook procedure to monitor the system for certain types of events.
        ''' These events are associated either with a specific thread
        ''' or with all threads in the same desktop as the calling thread.
        ''' For more info see here:
        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
        ''' </summary>
        ''' <param name="idHook">
        ''' The type of hook procedure to be installed.
        ''' </param>
        ''' <param name="lpfn">
        ''' A pointer to the hook procedure.
        ''' If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process,
        ''' the lpfn parameter must point to a hook procedure in a DLL.
        ''' Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
        ''' </param>
        ''' <param name="hInstance">
        ''' A handle to the DLL containing the hook procedure pointed to by the lpfn parameter.
        ''' The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by
        ''' the current process and if the hook procedure is within the code associated with the current process.
        ''' </param>
        ''' <param name="threadId">
        ''' The identifier of the thread with which the hook procedure is to be associated.
        ''' For desktop apps, if this parameter is zero, the hook procedure is associated
        ''' with all existing threads running in the same desktop as the calling thread.
        ''' </param>
        ''' <returns>
        ''' If the function succeeds, the return value is the handle to the hook procedure.
        ''' If the function fails, the return value is NULL.
        ''' </returns>
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
        Friend Shared Function SetWindowsHookEx(
               ByVal idHook As HookType,
               ByVal lpfn As LowLevelMouseProcDelegate,
               ByVal hInstance As IntPtr,
               ByVal threadId As UInteger
        ) As IntPtr
        End Function

        ''' <summary>
        ''' Removes a hook procedure installed in a hook chain by the 'SetWindowsHookEx' function.
        ''' For more info see here:
        ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ms644993%28v=vs.85%29.aspx
        ''' </summary>
        ''' <param name="idHook">
        ''' A handle to the hook to be removed.
        ''' This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
        ''' </param>
        ''' <returns>
        ''' If the function succeeds, the return value is nonzero.
        ''' If the function fails, the return value is zero.
        ''' </returns>
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)>
        Friend Shared Function UnhookWindowsHookEx(
               ByVal idHook As IntPtr
        ) As Boolean
        End Function

        ''' <summary>
        ''' Retrieves the current double-click time for the mouse.
        ''' A double-click is a series of two clicks of the mouse button,
        ''' the second occurring within a specified time after the first.
        ''' The double-click time is the maximum number of milliseconds that may occur
        ''' between the first and second click of a double-click.
        ''' The maximum double-click time is 5000 milliseconds.
        ''' </summary>
        ''' <returns>
        ''' The return value specifies the current double-click time, in milliseconds.
        ''' The maximum return value is 5000 milliseconds.
        ''' </returns>
        <DllImport("user32.dll", CharSet:=CharSet.Auto)>
        Friend Shared Function GetDoubleClickTime() As Integer
        End Function

#End Region

#Region " Enumerations "

        ''' <summary>
        ''' Indicates a type of Hook procedure to be installed.
        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx
        ''' </summary>
        <Description("Enum used in 'idHook' parameter of 'SetWindowsHookEx' function.")>
        Friend Enum HookType As UInteger

            ' **************************************
            ' This enumeration is partially defined.
            ' **************************************

            ''' <summary>
            ''' Installs a hook procedure that monitors low-level mouse input events.
            ''' For more information, see the LowLevelMouseProc hook procedure.
            ''' </summary>
            WH_MOUSE_LL = 14UI

        End Enum

        ''' <summary>
        ''' The event-injected flags.
        ''' An application can use the following values to test the flags.
        ''' Testing LLMHF_INJECTED (bit 0) will tell you whether the event was injected.
        ''' If it was, then testing LLMHF_LOWER_IL_INJECTED (bit 1) will tell you
        ''' whether or not the event was injected from a process running at lower integrity level.
        ''' </summary>
        <Flags()>
        <Description("Enum used in 'flags' parameter of 'MSLLHOOKSTRUCT' structure.")>
        Public Enum MSLLHOOKSTRUCTFlags As Integer

            ''' <summary>
            ''' Test the event-injected (from any process) flag.
            ''' </summary>
            LLMHF_INJECTED = 1I

            ''' <summary>
            ''' Test the event-injected (from a process running at lower integrity level) flag.
            ''' </summary>
            LLMHF_LOWER_IL_INJECTED = 2I

        End Enum

#End Region

#Region " Structures "

        ''' <summary>
        ''' The POINT structure defines the x- and y- coordinates of a point.
        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162805%28v=vs.85%29.aspx
        ''' </summary>
        <Description("Structure used in 'pt' parameter of 'MSLLHOOKSTRUCT' structure.")>
        <StructLayout(LayoutKind.Sequential)>
        Friend Structure POINT

            ''' <summary>
            ''' The x-coordinate of the point.
            ''' </summary>
            Friend X As Integer

            ''' <summary>
            ''' The y-coordinate of the point.
            ''' </summary>
            Friend Y As Integer

        End Structure

        ''' <summary>
        ''' Contains information about a low-level mouse input event.
        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644970%28v=vs.85%29.aspx
        ''' </summary>
        <Description("Structure used in 'lParam' parameter of 'CallNextHookEx' function.")>
        Friend Structure MSLLHOOKSTRUCT

            ''' <summary>
            ''' The ptThe x- and y-coordinates of the cursor, in screen coordinates.
            ''' </summary>
            Friend pt As NativeMethods.POINT

            ''' <summary>
            ''' If the message is 'WM_MOUSEWHEEL', the high-order word of this member is the wheel delta.
            ''' The low-order word is reserved.
            ''' A positive value indicates that the wheel was rotated forward, away from the user;
            ''' a negative value indicates that the wheel was rotated backward, toward the user.
            ''' One wheel click is defined as 'WHEEL_DELTA', which is '120'.
            ''' </summary>
            Friend mouseData As Integer

            ''' <summary>
            ''' The event-injected flag.
            ''' </summary>
            Friend flags As MSLLHOOKSTRUCTFlags

            ''' <summary>
            ''' The time stamp for this message.
            ''' </summary>
            Friend time As UInteger

            ''' <summary>
            ''' Additional information associated with the message.
            ''' </summary>
            Friend dwExtraInfo As IntPtr

        End Structure

#End Region

#Region " Delegates "

        ''' <summary>
        ''' Delegate LowLevelMouseProc
        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx
        ''' </summary>
        ''' <returns>
        ''' If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
        ''' If nCode is greater than or equal to zero, and the hook procedure did not process the message,
        ''' it is highly recommended that you call CallNextHookEx and return the value it returns;
        ''' otherwise, other applications that have installed WH_MOUSE_LL hooks will not receive hook notifications
        ''' and may behave incorrectly as a result.
        ''' If the hook procedure processed the message,
        ''' 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.
        ''' </returns>
        Friend Delegate Function LowLevelMouseProcDelegate(
                ByVal nCode As IntPtr,
                ByVal wParam As IntPtr,
                ByVal lParam As IntPtr
        ) As Integer

#End Region

#Region " Hidden Methods "

        ''' <summary>
        ''' Determines whether the specified System.Object instances are considered equal.
        ''' </summary>
        <EditorBrowsable(EditorBrowsableState.Never)>
        Public Shadows Sub Equals()
        End Sub

        ''' <summary>
        ''' Determines whether the specified System.Object instances are the same instance.
        ''' </summary>
        <EditorBrowsable(EditorBrowsableState.Never)>
        Private Shadows Sub ReferenceEquals()
        End Sub

#End Region

    End Class

#End Region

#Region " Objects "

    ''' <summary>
    ''' Handle to the hook procedure.
    ''' </summary>
    Private MouseHook As IntPtr

    ''' <summary>
    ''' The mouse hook delegate.
    ''' </summary>
    Private MouseHookDelegate As NativeMethods.LowLevelMouseProcDelegate

#End Region

#Region " Properties "

    ''' <summary>
    ''' ** ONLY FOR TESTING PURPOSES **
    ''' Gets or sets a value indicating whether to suppress the last MouseUp event of
    ''' the specified clicked button when a double-click fires.
    '''
    ''' If this value is set to <c>true</c>, the application will send the events in this order for a Double-Click:
    ''' MouseDown, MouseUp, MouseDown, MouseDoubleClick
    '''
    ''' If this value is set to <c>false</c>, the application will send the events in this order for a Double-Click:
    ''' MouseDown, MouseUp, MouseDown, MouseUp, MouseDoubleClick
    '''
    ''' </summary>
    ''' <value><c>true</c> if MouseUp event is suppressed; otherwise <c>false</c>.</value>
    Friend Property SuppressMouseUpEventWhenDoubleClick As Boolean = False

    ''' <summary>
    ''' ** ONLY FOR TESTING PURPOSES **
    ''' Gets or sets the screen's working area.
    ''' The events fired by <see cref="MouseHook"/> are restricted to the bounds of the specified rectangle.
    ''' </summary>
    ''' <value>The screen's working area.</value>
    Friend Property WorkingArea As Rectangle
        Get
            Return Me._Workingarea
        End Get
        Set(ByVal value As Rectangle)
            Me._Workingarea = value
        End Set
    End Property

    ''' <summary>
    ''' The screen's working area
    ''' </summary>
    Private _Workingarea As Rectangle = SystemInformation.VirtualScreen

#End Region

#Region " Enumerations "

    ''' <summary>
    ''' Indicates a Windows Message related to a mouse events.
    ''' For more info see here:
    ''' http://msdn.microsoft.com/en-us/library/windows/desktop/ff468877%28v=vs.85%29.aspx
    ''' </summary>
    Private Enum MouseMessages As UInteger

        ''' <summary>
        ''' Posted to a window when the cursor moves.
        ''' If the mouse is not captured, the message is posted to the window that contains the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_MOUSEMOVE = &H200UI

        ''' <summary>
        ''' Posted when the user presses the left mouse button while the cursor is in the client area of a window.
        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_LBUTTONDOWN = &H201UI

        ''' <summary>
        ''' Posted when the user releases the left mouse button while the cursor is in the client area of a window.
        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_LBUTTONUP = &H202UI

        ''' <summary>
        ''' Posted when the user presses the right mouse button while the cursor is in the client area of a window.
        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_RBUTTONDOWN = &H204UI

        ''' <summary>
        ''' Posted when the user releases the right mouse button while the cursor is in the client area of a window.
        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_RBUTTONUP = &H205UI

        ''' <summary>
        ''' Posted when the user presses the middle mouse button while the cursor is in the client area of a window.
        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_MBUTTONDOWN = &H207UI

        ''' <summary>
        ''' Posted when the user releases the middle mouse button while the cursor is in the client area of a window.
        ''' If the mouse is not captured, the message is posted to the window beneath the cursor.
        ''' Otherwise, the message is posted to the window that has captured the mouse
        ''' </summary>
        WM_MBUTTONUP = &H208UI

        ''' <summary>
        ''' Sent to the active window when the mouse's horizontal scroll wheel is tilted or rotated.
        ''' The DefWindowProc function propagates the message to the window's parent.
        ''' There should be no internal forwarding of the message,
        ''' since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
        ''' </summary>
        WM_MOUSEWHEEL = &H20AUI

    End Enum

    ''' <summary>
    ''' Indicates the whell direction of the mouse.
    ''' </summary>
    Public Enum WheelDirection As Integer

        ''' <summary>
        ''' The wheel is moved up.
        ''' </summary>
        WheelUp = 1I

        ''' <summary>
        ''' The wheel is moved down.
        ''' </summary>
        WheelDown = 2I

    End Enum

#End Region

#Region " Events "

    ''' <summary>
    ''' Occurs when the mouse moves.
    ''' </summary>
    Friend Event MouseMove(ByVal sender As Object,
                           ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse left button is pressed.
    ''' </summary>
    Friend Event MouseLeftDown(ByVal sender As Object,
                               ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse left button is released.
    ''' </summary>
    Friend Event MouseLeftUp(ByVal sender As Object,
                             ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse left button performs a double-click.
    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
    ''' </summary>
    Friend Event MouseLeftDoubleClick(ByVal sender As Object,
                                      ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse right button is pressed.
    ''' </summary>
    Friend Event MouseRightDown(ByVal sender As Object,
                                ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse right button is released.
    ''' </summary>
    Friend Event MouseRightUp(ByVal sender As Object,
                              ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse right button performs a double-click.
    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
    ''' </summary>
    Friend Event MouseRightDoubleClick(ByVal sender As Object,
                                       ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse middle button is pressed.
    ''' </summary>
    Friend Event MouseMiddleDown(ByVal sender As Object,
                                 ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse middle button is released.
    ''' </summary>
    Friend Event MouseMiddleUp(ByVal sender As Object,
                               ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse middle button performs a double-click.
    ''' A double click is considered as: (MouseLeftDown + MouseLeftUp) * 2
    ''' </summary>
    Friend Event MouseMiddleDoubleClick(ByVal sender As Object,
                                        ByVal MouseLocation As Point)

    ''' <summary>
    ''' Occurs when the mouse wheel is moved up or down.
    ''' </summary>
    Friend Event MouseWheel(ByVal sender As Object,
                            ByVal MouseLocation As Point,
                            ByVal WheelDirection As WheelDirection)

#End Region

#Region " Constructors "

    ''' <summary>
    ''' Prevents a default instance of the <see cref="MouseHook"/> class from being created.
    ''' </summary>
    Private Sub New()
    End Sub

    ''' <summary>
    ''' Initializes a new instance of the <see cref="MouseHook"/> class.
    ''' </summary>
    ''' <param name="Install">
    ''' If set to <c>true</c>, the Hook starts initialized for this <see cref="MouseHook"/> instance.
    ''' </param>
    Friend Sub New(Optional ByVal Install As Boolean = False)

        If Install Then
            Me.Install()
        End If

    End Sub

#End Region

#Region " Public Methods "

    ''' <summary>
    ''' Installs the Mouse Hook, then start processing messages to fire events.
    ''' </summary>
    Friend Sub Install()

        Me.MouseHookDelegate = New NativeMethods.LowLevelMouseProcDelegate(AddressOf LowLevelMouseProc)

        Try
            Me.MouseHook = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL,
                                                          Me.MouseHookDelegate,
                                                          Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)

        Catch ex As Exception
            Throw

        End Try

    End Sub

    ''' <summary>
    ''' Uninstalls the Mouse Hook and free all resources, then stop processing messages to fire events.
    ''' </summary>
    Friend Sub Uninstall()

        Me.Finalize()

    End Sub

#End Region

#Region " Private Methods "

    ''' <summary>
    ''' Processes the mouse windows messages and raises it's corresponding events.
    ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644986%28v=vs.85%29.aspx
    ''' </summary>
    ''' <param name="nCode">
    ''' A code the hook procedure uses to determine how to process the message.
    ''' If nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function
    ''' without further processing and should return the value returned by CallNextHookEx.
    ''' </param>
    ''' <param name="wParam">The identifier of the mouse message.</param>
    ''' <param name="lParam"> A pointer to an <see cref="NativeMethods.MSLLHOOKSTRUCT"/> structure.</param>
    ''' <returns>
    ''' If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
    ''' If nCode is greater than or equal to zero, and the hook procedure did not process the message,
    ''' it is highly recommended that you call CallNextHookEx and return the value it returns;
    ''' otherwise, other applications that have installed WH_MOUSE_LL hooks will not receive hook notifications
    ''' and may behave incorrectly as a result.
    ''' If the hook procedure processed the message,
    ''' 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.
    ''' </returns>
    Private Function LowLevelMouseProc(ByVal nCode As Integer,
                                       ByVal wParam As MouseMessages,
                                       ByVal lParam As IntPtr) As Integer

        Static LeftClickTime As Integer = 0I ' Determines a left button double-click.
        Static RightClickTime As Integer = 0I ' Determines a right button double-click.
        Static MiddleClickTime As Integer = 0I ' Determines a middle button double-click.

        If nCode = 0I Then

            Dim x As Integer
            Dim y As Integer

            Dim MouseStruct As NativeMethods.MSLLHOOKSTRUCT
            MouseStruct = CType(Marshal.PtrToStructure(lParam, MouseStruct.GetType()),
                                NativeMethods.MSLLHOOKSTRUCT)

            ' Fix X coordinate.
            Select Case MouseStruct.pt.X

                Case Is <= 0I
                    If MouseStruct.pt.X >= Me.WorkingArea.Location.X Then
                        x = MouseStruct.pt.X

                    ElseIf MouseStruct.pt.X <= Me.WorkingArea.Location.X Then

                        If MouseStruct.pt.X <= (Me.WorkingArea.Location.X - Me.WorkingArea.Width) Then
                            x = (Me.WorkingArea.Location.X - Me.WorkingArea.Width)
                        Else
                            x = MouseStruct.pt.X
                        End If

                    End If

                Case Is >= Me.WorkingArea.Width
                    x = Me.WorkingArea.Width

                Case Else
                    x = MouseStruct.pt.X

            End Select

            ' Fix Y coordinate.
            Select Case MouseStruct.pt.Y

                Case Is >= Me.WorkingArea.Height
                    y = Me.WorkingArea.Height

                Case Is <= 0I
                    y = 0I

                Case Else
                    y = MouseStruct.pt.Y

            End Select

            If x <= Me.WorkingArea.Width _
            AndAlso y < Me.WorkingArea.Height _
            AndAlso MouseStruct.pt.X > Me.WorkingArea.Width Then

                Return 0

            ElseIf x <= Me.WorkingArea.Width _
            AndAlso y < Me.WorkingArea.Height _
            AndAlso MouseStruct.pt.X < Me.WorkingArea.X Then

                Return 0

            ElseIf x = Me.WorkingArea.Width _
            AndAlso y < Me.WorkingArea.Height Then

                If Not Me.WorkingArea.Contains(x - 1, y) Then
                    Return 0
                End If

            ElseIf x < Me.WorkingArea.Width _
            AndAlso y = Me.WorkingArea.Height Then

                If Not Me.WorkingArea.Contains(x, y - 1) Then
                    Return 0
                End If

            End If

            Select Case wParam

                Case MouseMessages.WM_MOUSEMOVE
                    RaiseEvent MouseMove(Me, New Point(x, y))

                Case MouseMessages.WM_LBUTTONDOWN
                    RaiseEvent MouseLeftDown(Me, New Point(x, y))

                Case MouseMessages.WM_LBUTTONUP
                    If LeftClickTime <> 0 Then
                        LeftClickTime = Environment.TickCount() - LeftClickTime
                    End If

                    If (LeftClickTime <> 0I) AndAlso (LeftClickTime < NativeMethods.GetDoubleClickTime()) Then
                        LeftClickTime = 0I
                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
                            RaiseEvent MouseLeftUp(Me, New Point(x, y))
                        End If
                        RaiseEvent MouseLeftDoubleClick(Me, New Point(x, y))

                    Else
                        LeftClickTime = Environment.TickCount()
                        RaiseEvent MouseLeftUp(Me, New Point(x, y))

                    End If

                Case MouseMessages.WM_RBUTTONDOWN
                    RaiseEvent MouseRightDown(Me, New Point(x, y))

                Case MouseMessages.WM_RBUTTONUP
                    If RightClickTime <> 0I Then
                        RightClickTime = Environment.TickCount() - RightClickTime
                    End If

                    If (RightClickTime <> 0I) AndAlso (RightClickTime < NativeMethods.GetDoubleClickTime()) Then
                        RightClickTime = 0I
                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
                            RaiseEvent MouseRightUp(Me, New Point(x, y))
                        End If
                        RaiseEvent MouseRightDoubleClick(Me, New Point(x, y))

                    Else
                        RightClickTime = Environment.TickCount()
                        RaiseEvent MouseRightUp(Me, New Point(x, y))

                    End If

                Case MouseMessages.WM_MBUTTONDOWN
                    RaiseEvent MouseMiddleDown(Me, New Point(x, y))

                Case MouseMessages.WM_MBUTTONUP
                    If MiddleClickTime <> 0I Then
                        MiddleClickTime = Environment.TickCount() - MiddleClickTime
                    End If

                    If (MiddleClickTime <> 0I) AndAlso (MiddleClickTime < NativeMethods.GetDoubleClickTime()) Then
                        MiddleClickTime = 0I
                        If Not Me.SuppressMouseUpEventWhenDoubleClick Then
                            RaiseEvent MouseMiddleUp(Me, New Point(x, y))
                        End If
                        RaiseEvent MouseMiddleDoubleClick(Me, New Point(x, y))

                    Else
                        MiddleClickTime = Environment.TickCount()
                        RaiseEvent MouseMiddleUp(Me, New Point(x, y))

                    End If

                Case MouseMessages.WM_MOUSEWHEEL
                    RaiseEvent MouseWheel(Me, New Point(x, y), If(MouseStruct.mouseData < 0I,
                                                                 WheelDirection.WheelDown,
                                                                 WheelDirection.WheelUp))

                Case Else
                    Exit Select ' Do Nothing

            End Select

            Return 0I

        ElseIf nCode < 0I Then
                Return NativeMethods.CallNextHookEx(MouseHook, nCode, wParam, lParam)

        Else ' nCode > 0
                Return -1I

        End If

    End Function

#End Region

#Region " Hidden Methods "

    ''' <summary>
    ''' Serves as a hash function for a particular type.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub GetHashCode()
    End Sub

    ''' <summary>
    ''' Gets the System.Type of the current instance.
    ''' </summary>
    ''' <returns>The exact runtime type of the current instance.</returns>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Function [GetType]()
        Return Me.GetType
    End Function

    ''' <summary>
    ''' Determines whether the specified System.Object instances are considered equal.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub Equals()
    End Sub

    ''' <summary>
    ''' Determines whether the specified System.Object instances are the same instance.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Private Shadows Sub ReferenceEquals()
    End Sub

    ''' <summary>
    ''' Returns a String that represents the current object.
    ''' </summary>
    <EditorBrowsable(EditorBrowsableState.Never)>
    Public Shadows Sub ToString()
    End Sub

#End Region

#Region "IDisposable Support"

    ''' <summary>
    ''' Flag to detect redundant calls at <see cref="Dispose"/> method.
    ''' </summary>
    Private disposedValue As Boolean

    ''' <summary>
    ''' Releases unmanaged and optionally managed resources.
    ''' </summary>
    ''' <param name="disposing">
    ''' <c>true</c> to release both managed and unmanaged resources;
    ''' <c>false</c> to release only unmanaged resources.
    ''' </param>
    Protected Sub Dispose(ByVal disposing As Boolean)

        If Not Me.disposedValue Then

            If disposing Then ' Dispose managed state (managed objects).

            Else ' Free unmanaged resources (unmanaged objects).
                NativeMethods.UnhookWindowsHookEx(Me.MouseHook)

            End If

        End If

        Me.disposedValue = True

    End Sub

    ''' <summary>
    ''' Allows an object to try to free resources
    ''' and perform other cleanup operations before it is reclaimed by garbage collection.
    ''' </summary>
    Protected Overrides Sub Finalize()

        ' Do not change this code. Put cleanup code in method: Dispose(ByVal disposing As Boolean)

        Me.Dispose(disposing:=False)
        MyBase.Finalize()

    End Sub

    ''' <summary>
    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    ''' </summary>
    Private Sub Dispose() Implements IDisposable.Dispose

        ' Do not change this code. Put cleanup code in method: Dispose(ByVal disposing As Boolean)

        Me.Dispose(disposing:=True)
        GC.SuppressFinalize(obj:=Me)

    End Sub

#End Region

End Class

#End Region