Jump to content

Recommended Posts

Posted

One more question.

This code temporarily freezes the key after it is activated.

If _ispressed('41') = 1 And DllStructGetData($tRIH, "hDevice") = 0x00010049 Then
            _BlockInputEx(3, "", "[a]")
             AdlibRegister("_Quit", 10000)
             MsgBox(64, 'Result', 'key А - PS2')
EndIf

 

#include <BlockInputEx.au3>

http://www.autoitscript.com/forum/index.php?s=&showtopic=87735

How to prevent entering text from the keyboard (with handle number 0x00010049) from the moment the code is run ?

Posted

For that you got multiple ways. :) 

The first solution i thought is to disable the port used by this device. 

USB/ps2

Never did it but i guess it s possible.

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

  Reveal hidden contents

 

Posted

Have no idea, if you need to detect the key, then the code has to be able to "see" it, i think.

So if you block input it's like there is no key press.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

argumentum,It doesn't work. When triggered, the script still prints an unnecessary "a".

;Bilgus 2018
;Determine which keyboard was pressed

#include <Array.au3>
#include <WinAPISys.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Global Const $HWND_MESSAGE = (-3) ;create a message-only window when set as Parent

;RAWINPUTDEVICE Constants
Global Const $HID_USAGE_PAGE_GENERIC = 0x1
Global Const $HID_USAGE_GENERIC_KEYBOARD = 0x6

Global $ghSelectedDevice

Global $gaKeyboards = EnumRawKeyboards("\HID")

If IsArray($gaKeyboards) And $gaKeyboards[0][0] >= 1 Then $ghSelectedDevice = $gaKeyboards[1][0] ; hard coded change to suit

;_ArrayDisplay($gaKeyboards, '_WinAPI_EnumRawInputDevices', "", 0, Default, "Handle|Type|VID|Keys") ;Not Needed...

Global $hTarget = GUICreate("main", 10, 10, Default, Default, Default, Default, $HWND_MESSAGE) ;Dummy window to recieve messages

Register_RawInput($HID_USAGE_PAGE_GENERIC, $HID_USAGE_GENERIC_KEYBOARD, $RIDEV_INPUTSINK, $hTarget) ;$RIDEV_INPUTSINK recieves input when not foreground

; Register WM_INPUT message
GUIRegisterMsg($WM_INPUT, 'WM_INPUT')



While 1
    Sleep(1000)
WEnd

Func Device_Pressed()
    ConsoleWrite("Device Pressed" & @CRLF)
EndFunc   ;==>Device_Pressed

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func Register_RawInput($iUsagePage, $iUsage, $iFlags, $hTargetHwnd)
    Local $tRID = DllStructCreate($tagRAWINPUTDEVICE)
    DllStructSetData($tRID, 'UsagePage', $iUsagePage)
    DllStructSetData($tRID, 'Usage', $iUsage)
    DllStructSetData($tRID, 'Flags', $iFlags)
    DllStructSetData($tRID, 'hTarget', $hTargetHwnd)

    ; Register HID input to obtain info from devices
    _WinAPI_RegisterRawInputDevices($tRID)
EndFunc   ;==>Register_RawInput

Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam) ;Callback from RawInput
    #forceref $iMsg, $wParam

   Local $tInfo, $aData = _WinAPI_EnumRawInputDevices()
   Local $_tagRID_INFO_KEYBOARD = $tagRID_INFO_KEYBOARD
   Local $tInfo, $tDeviceName, $sDeviceName


    ;'struct;dword Type;dword Size;handle hDevice;wparam wParam;endstruct'
    Local $tRIH = DllStructCreate($tagRAWINPUTHEADER)

     If _WinAPI_GetRawInputData($lParam, $tRIH, DllStructGetSize($tRIH), $RID_HEADER) And DllStructGetData($tRIH, "Type") = $RIM_TYPEKEYBOARD Then
        ;ConsoleWrite("0x" & Hex(DllStructGetData($tRIH, "hDevice")) & @CRLF)
        If $ghSelectedDevice = DllStructGetData($tRIH, "hDevice") Then
            ;ConsoleWrite("Device Pressed" & @CRLF)
        Else
            ;ConsoleWrite("Different Device Pressed" & @CRLF)
        EndIf
        If _ispressed('41') = 1 And DllStructGetData($tRIH, "hDevice") = 0x00010049 Then
            ;ConsoleWrite('Yes A' &@CRLF)
            MsgBox(64, 'Result', 'Key А - PS2')
         EndIf

        If _ispressed('41') = 1 And DllStructGetData($tRIH, "hDevice") = $HandleX Then
            ;ConsoleWrite('Yes A' &@CRLF)
            MsgBox(64, 'Result', 'Key А - USB')
        EndIf
     EndIf

    Return 1
    Return $GUI_RUNDEFMSG ;Pass on to default winproc
EndFunc   ;==>WM_INPUT

Func EnumRawKeyboards($sDeviceNameMatch = "")
    ;Returns array of keyboard device IDs
    Local $tInfo, $aData = _WinAPI_EnumRawInputDevices()

    If IsArray($aData) Then
        Local $aKeyboards[$aData[0][0] + 1][4]

        ;'dword Size;dword Type;';'struct;dword KbType;dword KbSubType;dword KeyboardMode;dword NumberOfFunctionKeys;dword NumberOfIndicators;dword NumberOfKeysTotal;endstruc'
        Local $_tagRID_INFO_KEYBOARD = $tagRID_INFO_KEYBOARD

        If StringRight($_tagRID_INFO_KEYBOARD, 1) <> "t" Then $_tagRID_INFO_KEYBOARD &= "t" ; t is missing from endstruct

        Local $iCt = 0, $iSz
        Local $tInfo, $tDeviceName, $sDeviceName

        For $i = 1 To $aData[0][0]
            $tInfo = DllStructCreate($_tagRID_INFO_KEYBOARD)

            If _WinAPI_GetRawInputDeviceInfo($aData[$i][0], $tInfo, DllStructGetSize($tInfo), $RIDI_DEVICEINFO) And $aData[$i][1] = $RIM_TYPEKEYBOARD Then
                $iSz = _WinAPI_GetRawInputDeviceInfo($aData[$i][0], 0, 0, $RIDI_DEVICENAME) ;Get bytes needed
                $tDeviceName = DllStructCreate('wchar[' & $iSz + 1 & ']') ;Holds device name string

                If _WinAPI_GetRawInputDeviceInfo($aData[$i][0], $tDeviceName, DllStructGetSize($tDeviceName), $RIDI_DEVICENAME) Then
                    $sDeviceName = DllStructGetData($tDeviceName, 1)

                    If $sDeviceNameMatch <> "" And Not StringInStr($sDeviceName, $sDeviceNameMatch) Then ContinueLoop

                    $iCt += 1
                    $aKeyboards[$iCt][0] = $aData[$i][0] ;Handle
                    $aKeyboards[$iCt][1] = $aData[$i][1] ;Type
                    $aKeyboards[$iCt][2] = $sDeviceName
                    $aKeyboards[$iCt][3] = DllStructGetData($tInfo, "NumberOfKeysTotal")
                    Global $HandleX = $aData[1][0]

                EndIf

            EndIf
        Next
        $aKeyboards[0][0] = $iCt ; Write count of keyboard devices to array
        ReDim $aKeyboards[$iCt + 1][4] ;Resize array
    EndIf
    Return $aKeyboards
 EndFunc   ;==>EnumRawKeyboards

 

Posted (edited)

Ah yes, i see what you did there.

 

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

In order to block the key presses it starts getting complicated

I made a hooking DLL in FASM assembly that worked decently but not perfectly I don't remember exactly where I was in this code so don't expect too much

  Reveal hidden contents

The problem is that you need to delay keypresses until the device is known and windows registers a keypress prior to filling the info in GetRawInputData

this makes it unsuitable imo.

 

Next I tried my own low level keyboard driver but then you need to turn test signing on to use it.

I tried a keyboard driver that is specifically made for this called Interception

http://www.oblita.com/interception.html

I really like the idea but dislike the lack of source code but this is probably your best bet

Edit: Looks like there is source code:

https://github.com/oblitum/Interception/tree/master/library

 

Edited by Bilgus
Posted (edited)

Did you try modifying argumentum's code? or the code i posted with your keyboard handle? ;)

EDIT: Removed

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

  • Moderators
Posted

Hi,

Last warning - I have just had to delete yet another "keylogger" code example from this thread. Remember the restrictions set out by Jon: "checking for a few keys" is fine - "looking for the whole keyboard" most definitely is not.

As it seems most people posting here are trying hard to keep within those bounds I am letting the thread run for the moment, but one more transgression and I will be forced to close it - and deal with whoever cannot understand the simple rules that apply.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

carecaYour script works !

But this script disables keys on all keyboards.

How to use your script for only one keyboard (marked "Different Device Pressed") ?

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
  • Recently Browsing   0 members

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