Jump to content

WM_Input but with Keypress


Recommended Posts

I've done this from other examples and working with Mouse Button 4, but I want to add some other options when I press a key from the keyboard and I don't know how to proceed.

I think the problem is that it only detects the inputs from the mouse, but I don't know how to add the keyboard as well without losing the mouse in the attempt.

Could someone help me?

#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Timers.au3>
#include <Misc.au3>
Opt("WinTitleMatchMode", 2)

#RequireAdmin

Global Const $RID_INPUT = 0x10000003
Global Const $RIDEV_INPUTSINK = 0x00000100
Global Const $RI_MOUSE_BUTTON_4_DOWN = 0x0040
Global Const $RI_MOUSE_BUTTON_4_UP = 0x0080 ;XBUTTON1 changed to up.
Global Const $RI_MOUSE_BUTTON_5_DOWN = 0x0100
Global Const $RI_MOUSE_BUTTON_5_UP = 0x0200 ;XBUTTON2 changed to up.
Global Const $RIM_TYPEMOUSE = 0
Global Const $RI_MOUSE_LEFT_BUTTON_DOWN = 0x0001 ;Self-explanatory
Global Const $RI_MOUSE_LEFT_BUTTON_UP = 0x0002 ;Self-explanatory
Global Const $RI_MOUSE_RIGHT_BUTTON_DOWN = 0x0004 ;Self-explanatory
Global Const $RI_MOUSE_RIGHT_BUTTON_UP = 0x0008 ;Self-explanatory
Global Const $RI_MOUSE_MIDDLE_BUTTON_DOWN = 0x0010 ;Self-explanatory
Global Const $RI_MOUSE_MIDDLE_BUTTON_UP = 0x0020 ;Self-explanatory
Global Const $RI_MOUSE_WHEEL = 0x0400 ;Raw input comes from a mouse wheel. The wheel delta is stored in usButtonData.


Global Const $S_Key = 0x000053 ; S Key input.

;If Not IsDeclared('WM_INPUT') Then Global Const $WM_INPUT = 0x00FF

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 $tagRAWINPUT_MOUSE = $tagRAWINPUTHEADER & $tagRAWMOUSE

;======================================
$hGUI = GUICreate("test") ; fake
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)


While 1
    Sleep(10)
WEnd


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

Func WM_INPUT($hwnd, $iMsg, $iwParam, $ilParam)
    Local $tRI_M, $pRI_M, $iRI_M, $iSize
    $tRI_M = DllStructCreate($tagRAWINPUT_MOUSE)
    $pRI_M = DllStructGetPtr($tRI_M)
    $iRI_M = DllStructGetSize($tRI_M)
    _GetRawInputData($ilParam, $RID_INPUT, $pRI_M, $iRI_M, $iRIH)

    Local $Flags = DllStructGetData($tRI_M, 'usButtonFlags')
        Select
            Case BitAND($Flags, $RI_MOUSE_BUTTON_4_DOWN)
                Local $hDLL = DllOpen("user32.dll")
                     Send("{F12 DOWN}")
                     Sleep(500)
                     Send("{F12 UP}")
        EndSelect
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUT

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

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   ;==>_GetRawInputData

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   ;==>_RegisterRawInputDevices
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...