Jump to content

Detect Special Mouse Key


 Share

Recommended Posts

Hi everyone, im struggling with this issue where im trying to capture a mouse keypress,

the application 'key tweak' detects the 2 keys, and output these 2 scancodes: 25 and 57421.

Looking at the forum and help file, the best i could come up with is this

$pStub_MouseProc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr")
$hHookMouse = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($pStub_MouseProc), _WinAPI_GetModuleHandle(0), 0)
ConsoleWrite('$hHookMouse - '& $hHookMouse &' - '&@MSEC&@CRLF)

But i don't understand it fully, and sure made mistakes, now im out of ideas.

Came for your wisdom and guidance.

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

I edited a help file example for you.

#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $g_hHook, $g_hStub_KeyProc, $g_sBuffer = ""

Example()

Func Example()
    OnAutoItExitRegister("Cleanup")

    Local $hMod

    $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hMod = _WinAPI_GetModuleHandle(0)
    $g_hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>Example



; ===========================================================
; callback function
; ===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf
    Switch $wParam
        Case $WM_LBUTTONDOWN
            ConsoleWrite("WM_LBUTTONDOWN" & @CRLF)
        Case $WM_LBUTTONUP
            ConsoleWrite("WM_LBUTTONUP" & @CRLF)
        Case $WM_MOUSEMOVE
;~          ConsoleWrite("WM_MOUSEMOVE" & @CRLF)
        Case $WM_MOUSEWHEEL
            ConsoleWrite("WM_MOUSEWHEEL" & @CRLF)
        Case $WM_MOUSEHWHEEL
            ConsoleWrite("WM_MOUSEHWHEEL" & @CRLF)
        Case $WM_RBUTTONDOWN
            ConsoleWrite("WM_RBUTTONDOWN" & @CRLF)
        Case $WM_RBUTTONUP
            ConsoleWrite("WM_RBUTTONUP" & @CRLF)
    EndSwitch


    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
EndFunc   ;==>Cleanup

Saludos

Link to comment
Share on other sites

Apreciate the help DanyFirex, but it's none of those buttons, it's a logitech performance MX, has 2 side buttons customizable with setpoint, the logitech application, the problem is that the application only simulates combinations of key presses, like ctrl/alt/shift+ something, so i would like to do a script that would detect what i call "special keys" because they're different than the others, and not detected with the scripts i found around, like this last one posted by DanyFirex. Also It's not X1 or X2, this will have to be something else "out of the box".

 Use
http://h--e.de/autoit/UDF/WhatKeyIsPressed.html
to get the hex scan codes.

 

I'll get on that asap, are you suggesting i use whatever code it retrieves, with _ispressed?

Best regards

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Does the special button only send ctrl/alt/shift+ something or do they send different combinations of ctrl/alt/shift like ctrl + alt + something? I would use a hotkeyset if you know the "something" variable for different scenarios. Are you setting the "something" manually or is that an internal thing with the mouse?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Apreciate the help DanyFirex, but it's none of those buttons, it's a logitech performance MX, has 2 side buttons customizable with setpoint, the logitech application, the problem is that the application only simulates combinations of key presses, like ctrl/alt/shift+ something, so i would like to do a script that would detect what i call "special keys" because they're different than the others, and not detected with the scripts i found around, like this last one posted by DanyFirex. Also It's not X1 or X2, this will have to be something else "out of the box".

I'll get on that asap, are you suggesting i use whatever code it retrieves, with _ispressed?

Best regards

If they're just sending a combination of regular keyboard keys then you can use _IsPressed to detect the keys.

Link to comment
Share on other sites

Does the special button only send ctrl/alt/shift+ something or do they send different combinations of ctrl/alt/shift like ctrl + alt + something? I would use a hotkeyset if you know the "something" variable for different scenarios. Are you setting the "something" manually or is that an internal thing with the mouse?

I see what you mean, it's a similar sugestion to the post after yours. To answer the question, i can set the something in the logitech setpoint app.

If they're just sending a combination of regular keyboard keys then you can use _IsPressed to detect the keys.

If i end up not finding a way to do it directly i'll be working on that. Thanks.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

 Use
http://h--e.de/autoit/UDF/WhatKeyIsPressed.html
to get the hex scan codes.

 

This is nice, but only detects these 2 mouse keys if i set them to emulate a normal key, there must be a way to scan it raw or something.

Seems like all sugestions revolve on the same thing, i was hoping some code that could detect the mouse at a low level, but the code i posted also doesn't detect them.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Here is a code which works with my Logitech M705
You - probably - will have to suit it to work with your mouse

#include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>
#Include <APISysConstants.au3>
HotKeySet('{ESC}', '_Exit')

Global Const $tagRAWINPUTDEVICE = 'ushort usUsagePage;ushort usUsage;dword dwFlags;hwnd hwndTarget;'
Global Const $tagRAWINPUTHEADER = 'dword dwType;dword dwSize;hwnd hDevice;uint_ptr wParam;'
Global Const $tagRAWMOUSE = 'ushort usFlags;ushort usAlignment;ushort usButtonFlags;' & _
    'ushort usButtonData;ulong ulRawButtons;long lLastX;long lLastY;ulong ulExtraInformation'
Global Const $tagRAWINPUTMOUSE = $tagRAWINPUTHEADER & $tagRAWMOUSE

;======================================
Global $tRIH, $iRIH
Global $hGUI, $label, $action

$hGUI = GUICreate('MyGUI', 120, 60, 20, 20,  -1, $WS_EX_TOPMOST)
$label = GUICtrlCreateLabel("test", 30, 20, 50, 20)
GUIRegisterMsg($WM_INPUT, 'WM_INPUT')

$tRID_M = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_M = DllStructGetPtr($tRID_M)
$iRID_M = DllStructGetSize($tRID_M)

$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)

DllStructSetData($tRID_M, 'usUsagePage', 0x01)
DllStructSetData($tRID_M, 'usUsage', 0x02)
DllStructSetData($tRID_M, 'dwFlags', $RIDEV_INPUTSINK) 
DllStructSetData($tRID_M, 'hwndTarget', $hGUI)

_RegisterRawInputDevices($pRID_M, 1, $iRID_M)
GUISetState()


While GuiGetMsg()<>$GUI_EVENT_CLOSE
    Sleep(10)
WEnd

 ;_Exit()

;=========================================

Func WM_INPUT($hwnd, $iMsg, $iwParam, $ilParam)

Local $tRI_M, $pRI_M, $iRI_M, $iSize
$tRI_M = DllStructCreate($tagRAWINPUTMOUSE)
$pRI_M = DllStructGetPtr($tRI_M)
$iRI_M = DllStructGetSize($tRI_M)
_GetRawInputData($ilParam, $RID_INPUT, $pRI_M, $iRI_M, $iRIH)

Switch DllStructGetData($tRI_M, 'dwType')
    Case $RIM_TYPEMOUSE

#cs
msgbox(0,"", "dwType   " & DllStructGetData($tRI_M, 'dwType') &@crlf & _
    "dwSize    " & DllStructGetData($tRI_M, 'dwSize')  &@crlf & _
    "hDevice   " & DllStructGetData($tRI_M, 'hDevice')  &@crlf & _
    "wParam   " & DllStructGetData($tRI_M, 'wParam')  &@crlf  &@crlf & _
    "usFlags        " & DllStructGetData($tRI_M, 'usFlags') &@crlf & _
    "usButtonFlags  " & DllStructGetData($tRI_M, 'usButtonFlags')  &@crlf & _
    "usButtonData  " & DllStructGetData($tRI_M, 'usButtonData')  &@crlf & _
    "ulRawButtons  " & DllStructGetData($tRI_M, 'ulRawButtons')  &@crlf & _
    "lLastX     " & DllStructGetData($tRI_M, 'lLastX')  &@crlf & _
    "lLastY     " & DllStructGetData($tRI_M, 'lLastY')  &@crlf & _
    "ulExtraInformation  " & DllStructGetData($tRI_M, 'ulExtraInformation'))
#ce

        Local $Flags = DllStructGetData($tRI_M, 'usButtonFlags')
        If not BitAND($Flags, BitOR($RI_MOUSE_MIDDLE_BUTTON_UP, _ 
            $RI_MOUSE_LEFT_BUTTON_UP, _ 
            $RI_MOUSE_RIGHT_BUTTON_UP, _ 
            $RI_MOUSE_BUTTON_4_UP, _ 
            $RI_MOUSE_BUTTON_5_UP)) Then
            If DllStructGetData($tRI_M, 'lLastX')=0 AND DllStructGetData($tRI_M, 'lLastY')=0 Then
                $btn = DllStructGetData($tRI_M, 'usButtonFlags')
                    Switch $btn
                    Case 1
                         $res = "left"
                    Case 4
                         $res = "right"
                    Case 16
                         $res = "btn wheel"
                    Case 64
                         $res = "btn side 1"
                    Case 256
                         $res = "btn side 2"
                    Case 1024
                         $res = "wheel"
                    Case else
                         $res = "undefined"
                    EndSwitch
                GuiCtrlSetData($label, $res)
            EndIf
        EndIf
EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc

;===================================
Func _Exit()
    Exit 
EndFunc

Func _GetRawInputData($hRawInput, $iCommand, $pData, ByRef $iSize, $iSizeHeader, $hDll = 'user32.dll')
    Local $aRet 
    $aRet = DllCall($hDll, 'uint', 'GetRawInputData', 'hwnd', $hRawInput, 'uint', $iCommand, 'ptr', $pData, 'uint*', $iSize, 'uint', $iSizeHeader)  
    If @error Or $aRet[0] = 4294967295 Then Return SetError(1, 0, $aRet[0])
    $iSize = $aRet[4]
    Return $aRet[0]
EndFunc

Func _RegisterRawInputDevices($pRawInputDevices, $iNumDevices, $iSize, $hDll = 'user32.dll')
    Local $aRet 
    $aRet = DllCall($hDll, 'int', 'RegisterRawInputDevices', 'ptr', $pRawInputDevices, 'uint', $iNumDevices, 'uint', $iSize)    
    If @error Or $aRet[0] = 0 Then SetError(1, 0, 0)
    Return $aRet[0]
EndFunc

 

Edited by mikell
Link to comment
Share on other sites

@mikell: This seems to be what im looking after, it's a matter of making it work and then grab the output number and work it like you did to your mouse.

So i had to add some stuff to the code because of syntax errors and stuff, and then i added a consolewrite to see the output numbers, and weirdly it always outputs 0, and the window shows undefined, whatever i do to the mouse, primary/sec clicks, wheel etc all show undefined and 0, shoudn't

$btn

vary depending on what i press in the mouse??

Local $Flags = DllStructGetData($tRI_M, 'usButtonFlags')
        If not BitAND($Flags, BitOR($RI_MOUSE_MIDDLE_BUTTON_UP, _
            $RI_MOUSE_LEFT_BUTTON_UP, _
            $RI_MOUSE_RIGHT_BUTTON_UP, _
            $RI_MOUSE_BUTTON_4_UP, _
            $RI_MOUSE_BUTTON_5_UP)) Then
            If DllStructGetData($tRI_M, 'lLastX')=0 AND DllStructGetData($tRI_M, 'lLastY')=0 Then
                $btn = DllStructGetData($tRI_M, 'usButtonFlags')
                    Switch $btn
                    Case 1
                         $res = 'left'
                    Case 4
                         $res = 'right'
                    Case 16
                         $res = 'btn wheel'
                    Case 64
                         $res = 'btn side 1'
                    Case 256
                         $res = 'btn side 2'
                    Case 1024
                         $res = 'wheel'
                    Case else
                         $res = 'undefined'
                    EndSwitch
                    ConsoleWrite('$btn - '& $btn &' - '&@MSEC&@CRLF);==================== always zero
                GuiCtrlSetData($label, $res)
            EndIf
        EndIf

And this is the full thing as im testing it.

#include 'GUIConstantsEx.au3'
#Include 'WindowsConstants.au3'
#Include 'APISysConstants.au3'
HotKeySet('{ESC}', '_Exit')

Global Const $tagRAWINPUTDEVICE = 'ushort usUsagePage;ushort usUsage;dword dwFlags;hwnd hwndTarget;'
Global Const $tagRAWINPUTHEADER = 'dword dwType;dword dwSize;hwnd hDevice;uint_ptr wParam;'
Global Const $tagRAWMOUSE = 'ushort usFlags;ushort usAlignment;ushort usButtonFlags;' & _
    'ushort usButtonData;ulong ulRawButtons;long lLastX;long lLastY;ulong ulExtraInformation'
Global Const $tagRAWINPUTMOUSE = $tagRAWINPUTHEADER & $tagRAWMOUSE

;======================================
Global $tRIH, $iRIH
Global $hGUI, $label, $action

$hGUI = GUICreate('MyGUI', 120, 60, 20, 20,  -1, $WS_EX_TOPMOST)
$label = GUICtrlCreateLabel('test', 30, 20, 50, 20)
GUIRegisterMsg($WM_INPUT, 'WM_INPUT')

$tRID_M = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_M = DllStructGetPtr($tRID_M)
$iRID_M = DllStructGetSize($tRID_M)

$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)

DllStructSetData($tRID_M, 'usUsagePage', 0x01)
DllStructSetData($tRID_M, 'usUsage', 0x02)
DllStructSetData($tRID_M, 'dwFlags', $RIDEV_INPUTSINK)
DllStructSetData($tRID_M, 'hwndTarget', $hGUI)

_RegisterRawInputDevices($pRID_M, 1, $iRID_M)
GUISetState()


While GuiGetMsg()<>$GUI_EVENT_CLOSE
    Sleep(10)
WEnd

 ;_Exit()

;=========================================

Func WM_INPUT($hwnd, $iMsg, $iwParam, $ilParam)

Local $tRI_M, $pRI_M, $iRI_M, $iSize
$tRI_M = DllStructCreate($tagRAWINPUTMOUSE)
$pRI_M = DllStructGetPtr($tRI_M)
$iRI_M = DllStructGetSize($tRI_M)
_GetRawInputData($ilParam, $RID_INPUT, $pRI_M, $iRI_M, $iRIH)

Switch DllStructGetData($tRI_M, 'dwType')
    Case $RIM_TYPEMOUSE

        Local $Flags = DllStructGetData($tRI_M, 'usButtonFlags')
        If not BitAND($Flags, BitOR($RI_MOUSE_MIDDLE_BUTTON_UP, _
            $RI_MOUSE_LEFT_BUTTON_UP, _
            $RI_MOUSE_RIGHT_BUTTON_UP, _
            $RI_MOUSE_BUTTON_4_UP, _
            $RI_MOUSE_BUTTON_5_UP)) Then
            If DllStructGetData($tRI_M, 'lLastX')=0 AND DllStructGetData($tRI_M, 'lLastY')=0 Then
                $btn = DllStructGetData($tRI_M, 'usButtonFlags')
                    Switch $btn
                    Case 1
                         $res = 'left'
                    Case 4
                         $res = 'right'
                    Case 16
                         $res = 'btn wheel'
                    Case 64
                         $res = 'btn side 1'
                    Case 256
                         $res = 'btn side 2'
                    Case 1024
                         $res = 'wheel'
                    Case else
                         $res = 'undefined'
                    EndSwitch
                    ConsoleWrite('$btn - '& $btn &' - '&@MSEC&@CRLF)
                GuiCtrlSetData($label, $res)
            EndIf
        EndIf
EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc

;===================================
Func _Exit()
    Exit
EndFunc

Func _GetRawInputData($hRawInput, $iCommand, $pData, ByRef $iSize, $iSizeHeader, $hDll = 'user32.dll')
    Local $aRet
    $aRet = DllCall($hDll, 'uint', 'GetRawInputData', 'hwnd', $hRawInput, 'uint', $iCommand, 'ptr', $pData, 'uint', $iSize, 'uint', $iSizeHeader)
    If @error Or $aRet[0] = 4294967295 Then Return SetError(1, 0, $aRet[0])
    $iSize = $aRet[4]
    Return $aRet[0]
EndFunc

Func _RegisterRawInputDevices($pRawInputDevices, $iNumDevices, $iSize, $hDll = 'user32.dll')
    Local $aRet
    $aRet = DllCall($hDll, 'int', 'RegisterRawInputDevices', 'ptr', $pRawInputDevices, 'uint', $iNumDevices, 'uint', $iSize)
    If @error Or $aRet[0] = 0 Then SetError(1, 0, 0)
    Return $aRet[0]
EndFunc

 

EDIT: turns out that in _GetRawInputData the condition $aRet[0] = 4294967295 is always true, here.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Thanks, Nice find, not sure how it disappeared, but it still doesn't find it, only the other ones. :( Any other sugestions?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...