Jump to content
Sign in to follow this  
crashdemons

USB Lock v6

Recommended Posts

crashdemons

Note: This is completely unrelated to the program offered on TuCows and CNET, I named it without ever checking the title, and I may decide to change it at will.

Posted Image

Posted Image

What Does it do?

This program allows you to require a specific drive (USB preferably) to be connected to the computer to gain access while the program is running.

Downloads:

USBLock.zip (Includes Source code, Compiled version, and English .LANG file)

UPDATES: (click "see post" to see notes on changes)

Version 6: see post

Version 5: see post

Version 4: see post

Version 3: see post

Version 2: see post

-----------------------------------

-How does it do it?

1a. On a normal run, the program will ask you for a drive letter to assign as a "Key Drive".

1b. A drive letter is assigned by command-line parameter.

1c. The "auto" parameter is used, and we skip to Step 4.

2. The Program will then generate a random keyfile, save a hash of the keyfile locally and save the actual keyfile on the root of the chosen/validated drive.

3. Waits until the keydrive is removed.

4. BlockInput is called

5. Then the program then checks repeatedly for the existence of the keyfile on all drives

6. The keyfile is validated, if it is valid, BlockInput is released and we return tp Step 2.

7. Assuming the keyfile is invalid, it is deleted and we return to step 5.

Note: There is a special keyfile that can be saved on a drive that will shut down the program to allow emergency access.

(if you edit the emergency text in the script, you will need to edit your own emergency keyfile)

USBLock_Emergency_Keyfile.zip

Requirements:

WindowsConstants.au3

GUIConstants.au3

StaticConstants.au3

String.au3

Misc.au3

myToast.au3 - by me (given)

MD5.au3 - which is either by:

- Ward (Using CallWindowProc; I suggest this one.)

- Frez Systems Ltd and SvenP (all AutoIt)

- Other

Credits:

Monitor On/Off Example - MrCreatoR

MD5 - SvenP or Ward

... let me know if you were missed for credit.

EDIT: fixed the "steps" explanation

5-5-13 Edit: Re-added images to post

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
ludocus

I tried this, But when I remove my drive it says it locks my computer but then those nothing..

It doesn't lock my computer.

And why don't you use something like this: ?

#include <File.au3>
While 1
$flash   = DriveGetDrive("removable")
if @Error then
Else
    if FindKey($flash[1]) Then
        msgbox ( 32+0, 'correct', 'this is the correct drive' )
    EndIf
    
EndIf
WEnd






Func FindKey($sDrive, $sD = 0, $sFile = 'key.opal', $sCreate = 0)
    if $sD = 1 then 
        if FileExists($sDrive&$sFile) Then
            FileDelete($sDrive&$sFile)
            if @error then
                return SetError(1, 1)
            Else
                return SetError(-1, -1)
            EndIf
        Else
            return -1
        EndIf
    EndIf
    If FileExists($sDrive&$sFile ) Then
        return 1
    Else
        if $sCreate = 1 then _FileCreate($sDrive&$sFile )
        return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
crashdemons

Sorry, redownload the ZIP - I had the script stuck with the "DebugMode" parameter enabled (Runs normally, but does not lock)

and to answer your second question; I do, essentially, do that - create a file and check for existence, but having wrote this myself I did it in the way I saw most efficient.


My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
ludocus

ok, I went on with my script.

And now I have about the same thing but then a lot smaller:

#include <File.au3>
#NoTrayIcon
$check = DriveGetDrive('removable')
if @error then 
    msgbox ( 16, 'Error', 'Please insert a drive before running this program' )
    Exit
EndIf

$times = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\UsbLocker", "times" )
if $times = '' Then
    msgbox ( 32, 'Welcome', 'This program will now write a key to your drive: '&$check[1]&@CRLF&'Enjoy this program, created by ludocus :)' )
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\UsbLocker", "times", 'REG_SZ', 38383 )
    FindKey($check[1], default, default, 1 )
EndIf

While 1
sleep ( 100 )
$flash   = DriveGetDrive("removable")
if @Error then
    LockOut('on')
Else
    if FindKey($flash[1]) Then
        LockOut('off')
    Else
        LockOut('on')
    EndIf
EndIf
WEnd

Func LockOut($sType)
    if $sType = 'off' Then
        if not ProcessExists('explorer.exe') then
            WinMinimizeAllUndo()
            run ('explorer.exe')
        EndIf
        
    Else
        WinMinimizeAll()
        If ProcessExists('explorer.exe') then ProcessClose('explorer.exe')
        if ProcessExists('taskmgr.exe') then ProcessClose('taskmgr.exe')
        if ProcessExists('cmd.exe') then ProcessClose('cmd.exe')
    EndIf
EndFunc





Func FindKey($sDrive, $sD = 0, $sFile = 'key.opal', $sCreate = 0)
    if $sD = 1 then 
        if FileExists($sDrive&$sFile) Then
            FileDelete($sDrive&$sFile)
            if @error then
                return SetError(1, 1)
            Else
                return SetError(-1, -1)
            EndIf
        Else
            return -1
        EndIf
    EndIf
    If FileExists($sDrive&$sFile ) Then
        return 1
    Else
        if $sCreate = 1 then _FileCreate($sDrive&$sFile )
        return 0
    EndIf
EndFunc

Maybe usefull?

Share this post


Link to post
Share on other sites
crashdemons

now I have about the same thing

Not really.

Don't be offended if I decide not to use your script.

I don't see the need to close Explorer or Cmd if I'm already locking out user input - And I'd rather not restrict the drive to removable drives.

(The only reason I don't check A, B and C is because A B and C are, usually, always mounted drives.)

I also don't agree with writing to the registry unnecessarily.

Feel free to continue your application in another thread :)

Edit: I also see that you repeatedly minimize all windows, not blocking input?

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
ludocus

ok, :)

I will not put the code in another thread because I made it to help you not to make a new topic :(

Share this post


Link to post
Share on other sites
crashdemons

My application works fine for now, thanks :)

Just as long as I make sure to turn off the occasional debug parameter.


My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
Ev0lving

I get a error, once compiled using beta, I get the following

Line -1:

Error: Variable Used without being declared

I use windows vista x86 with sp1

Edited by Ev0lving

Share this post


Link to post
Share on other sites
spudw2k

Pretty cool. If I had my druthers, I'd use a hardware_id instead of a key. Also If you want to prevent Ctrl+Alt+Del take a look at the code in this thread.

Edited by spudw2k

Share this post


Link to post
Share on other sites
b0ris

Pretty cool. If I had my druthers, I'd use a hardware_id instead of a key. Also If you want to prevent Ctrl+Alt+Del take a look at the code in this thread.

Isn't it just easier to get the serial of the device? That's also unique, and just one line of code :P

Share this post


Link to post
Share on other sites
spudw2k

Share this post


Link to post
Share on other sites
crashdemons

UPDATE: Version 2

Updated includes files for newer AutoIt versions. (3.2.12.1 tested)

Supports two different styles of MD5.au3 (see first post for suggestions)

Pretty cool. If I had my druthers, I'd use a hardware_id instead of a key. Also If you want to prevent Ctrl+Alt+Del take a look at the code in this thread.

I would rather not marry the security of my computer to a specific drive without some sort of session-specific key.

Think of what might happen if you lock your PC and then lose your USB drive - someone could steal it and unlock your PC repeatedly.

However, the key I'm using is random and created on the keydrive (only the hash is saved on the locked system). This key is also renewed each time the drive unlocks the system.

So, even if someone copies the keyfile from your keydrive - if you unlock your system or quit USBLock, their key becomes invalid.

(However, the emergency key is an issue if they're aware of this software.; but you can always modify the emergency key text - edit the string starting with "~X@CD_USBLock")

Secondly, I'd rather not mess with system key combinations (like CTRL+ALT+DEL) that you're not supposed to block anyway.

- I COULD (although I'm not sure if I could do it in a simple method that would work for everyone) later use the serial or hardware id as part (but not all) of the identification for the keydrive.

NOTE: if you want to change how the "key" is determined just change what _GetNewKey() outputs.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
Ev0lving

Version 2.0

Very nice additions and very nice script, I am still able to input keystrokes and mousemovements in vista, the toast box comes up and tell me that my system is lock but I can still access it fully, I can help with getting it to work on Vista if you want.

Share this post


Link to post
Share on other sites
crashdemons

I'm guessing BlockInput fails if you do not run the program as admin [in Vista].

Failure: Already Enabled or #RequireAdmin not used.

I'll add #RequireAdmin to the script to fix this. Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
crashdemons

Version 2.0

Very nice additions and very nice script, I am still able to input keystrokes and mousemovements in vista, the toast box comes up and tell me that my system is lock but I can still access it fully, I can help with getting it to work on Vista if you want.

I Just updated the script to have #RequireAdmin as suggested by the help file.

Try the new version of it. (2.1+)

Thanks.


My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
crashdemons

Just updated again (3.0)

This time I added:

  • A GUI to list possible drive selections for your keydrive. (no fixed drives, no floppy drives, no CD-ROM's)
  • Tray Option to set a new keydrive while unlocked. (Remember - you can have only one valid keydrive set.)
  • Changes to Locked mode to secure your computer more immediately.
  • Changes to update the keyfiles more immediately.
  • Added some parameter settings. (see below)

Parameters:

  • "auto" - use a previously saved key hash, lock immediately without keydrive selection . (Good for Windows Startup if you already set a keydrive; example: "USBLock.exe auto")
  • Anything Else - the first character is used to specify a keydrive to silently set before Locked/Unlocked modes. (silent alternative to the selection GUI; example: "USBLock.exe D" for D:\)

Posted Image

Notes:

The GUI has (currently) a fixed width of 300 and will start another row if the number of drives goes beyond 300px wide.

(I would start smaller than 300 except the titlebar text becomes hidden)

Tell me if the GUI is displayed correctly in dimensions, etc.

Tell me also if the drive icons are incorrect for your operating system, as I can add conditions to modify the DriveIcons array.

(I only had a WinXP box to test the icons with.)

etc.

Included from first post to catalog/save space:

  • UI: Standard running mode now features a visual listing of valid drives to set as your keydrive.

    Close this window to Exit USBLock

    (If the drive icons are wrong for your OS, we can update!)

  • Security: The BlockInput and security checks are now done immediately upon 'lock' and all during the "secured" Toast display.
  • Options:

    The KeyDrive can now be changed to a new drive while in 'Unlocked' mode. (See Tray menu)

  • Parameters: Normally USBLock is ran without parameters.

    If you use the parameter 'auto' the computer is immediately locked with a previously saved key. (Windows Startup? :P )

    Otherwise, parameter text is used to silently select a new keydrive. ("ijk" sets drive I:\)

  • Other: The Tray Icon and Tooltip have been changed to show correctly in script mode.
  • Other: Keys are now updated immediately instead of after Toast notifications.
Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites
Ev0lving

Parameters:

  • "auto" - use a previously saved key hash, lock immediately without keydrive selection . (Good for Windows Startup if you already set a keydrive; example: "USBLock.exe auto")
  • Anything Else - the first character is used to specify a keydrive to silently set before Locked/Unlocked modes. (silent alternative to the selection GUI; example: "USBLock.exe D" for D:\)

Great additions to the script, I have one problem.. I am trying to use the auto Parameters with no luck, it just runs the program in vista and asks me to select a drive but there is no drive in the systema nd I want it to lock so the script exits and the system is un secure again. same as when I log off and log on again.

Edited by Ev0lving

Share this post


Link to post
Share on other sites
crashdemons

Great additions to the script, I have one problem.. I am trying to use the auto Parameters with no luck, it just runs the program in vista and asks me to select a drive but there is no drive in the systema nd I want it to lock so the script exits and the system is un secure again. same as when I log off and log on again.

Sorry, for the delayed response.

For not seeing your drives listed:

The following drives cannot be written to as a keydrive:

Drives with the letters A or B; Fixed drives; and CDROM/Optical drives.

However, everything but the floppy drives will be CHECKED for a valid keyfile - this allows you to make an emergency HDD, CD, etc. if your USB ports die.

To make this short:

Please insert a removable device that shows up in My Computer as a drive letter higher than C.

THEN start USBLock in normal mode and select it from the GUI.

(NOTE: USBLock cannot check for special USB devices that do not have drive letters, such as some cameras, MP3 players, etc.)

For problems using the "auto" mode:

To use "auto" mode, it would be in your best interest to satisfy two conditions first:

1. run USBLock in normal mode and select a removable drive as your keydrive

2. make sure USBLock is compiled so that you can use auto mode

- - - the command-line will look like "USBLock.exe auto" without the quotes.

Condition number 1 is important otherwise USBLock will be trying to automatically match a nonexistant keyfile. If a keyfile is NOT existant in auto mode, you may encounter very annoying results.

If you're seeing a drive-selection window when using a parameter, then that parameter is not being passed to the program

- "auto" and the drive selection parameters force USBLock to skip initial drive selection.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • BigMac121263
      By BigMac121263
      I know that this theme was discussed several times but I read all These threats with no helping result.
      I have two pieces of TEMPer1F USB Thermometer.
      It is a Standard Windows HID device with no add. Driver needed.
      With the device I got an App reading from it and showing Graphs and much more and which can handle several devices.
      With the Software came also a RDingUSB.dll file handling the communication with the device.
      I can call the dll without any error. But the Problem is how to Access the device using the DLL and Access more than one of same VID/PID
      by Serial or anything else useful.
      I have also sources in c# doing the Job, but no experience in C# to successfuly port it to AutoIT.
       
      So my question: Can anyone help me to realize the simple pull of the temperature value from the devices based on C# source?
      The rest to write it to MySQL DB and repeat it etc. is no Problem for me.
      ***************************************
      The C# part with the DLL functions class:
      ***************************************
      using System;
      using System.Runtime.InteropServices;
      namespace TEMPer
      {
        internal class RDing
        {
          [DllImport("RDingUSB.dll")]
          public static extern IntPtr OpenUSBDevice(int VID, int PID);
          [DllImport("RDingUSB.dll")]
          public static extern IntPtr CloseUSBDevice(IntPtr hDevice);
          [DllImport("RDingUSB.dll")]
          public static extern bool WriteUSB(IntPtr hDevice, byte[] pBuffer, uint dwBytesToWrite, ref ulong lpNumberOfBytesWritten);
          [DllImport("RDingUSB.dll")]
          public static extern bool ReadUSB(IntPtr hDevice, byte[] pBuffer, uint dwBytesToRead, ref ulong lpNumberOfBytesRead);
          [DllImport("RDingUSB.dll")]
          public static extern ushort GetInputLength(IntPtr hDevice);
          [DllImport("RDingUSB.dll")]
          public static extern ushort GetOutputLength(IntPtr hDevice);
          [DllImport("RDingUSB.dll")]
          public static extern uint GetErrorMsg(ref string[] lpErrorMsg, uint dwErrorMsgSize);
        }
      }
      *********************************
      The C# code snippet working with the functions of the class above is in the attachment
      this is the interesting part where the data is sent and pulled which I
      do not understand to transcode to AutoIT
      Important my devices are the type2 (TEMPer1F) :
      *********************************
      So in the end I Need: Call DLL, read all devices in array
      Loop the Array until ubound(Array) and for each device in Array read the temperature value and prepare the data to
      decimal 6,1 (SQL Format) and °C
      So how to pull the value from the devices?
      Maybe somwbody finds the important part in the C#  (the code above is for different models, mine is TEMPer1F
      Or maybe someone has solved this and has maybe a uDF for this
       
       
      MainForm.cs
    • WoodGrain
      By WoodGrain
      Hi All,
      I've bought a Ergodox EZ programmable keyboard with layers of key maps (eg, layer 0 = dvorak, layer 1 = numberpad & nav, layer 2 = qwerty, etc), I've also got a small USB screen that can pull information from the registry. What I would like to determine is a way to pull the value of each current key from the keyboard, I can then write the values to the registry and pull them into my USB screen so I can see the keyboard key layout.
      I'm stuck with retrieving the key values, I've looked at _IsPressed(), _WinAPI_GetKeyState(), _WinAPI_GetKeyboardState(), _WinAPI_GetKeyboardType(), _WinAPI_GetKeyNameText(), but none of them appear to be able to pull the keyboard key values without user interaction.
      The idea being, in pseudo code, bear in mind no error checking etc in this code, "GetKeyValue()" is what I'm needing help with and is a made up function, as is "HardwareKey1" etc:
      $keyOnePrev = "" $numOfKeys = 76 While 1 $keyOneCurrent = GetKeyValue(HardwareKey1) If $keyOneCurrent <> $keyOnePrev Then For $key = 1 To $numOfKeys $keyToWrite = GetKeyValue(HardwareKey & $key) RegWrite("HKEY_CURRENT_USER\Software\myKeyboard", "key" & $key, "REG_SZ", $keyToWrite) Next EndIf $keyOnePrev = $keyOneCurrent Sleep(5000) WEnd Thanks guys!
    • JRSmile
      By JRSmile
      Hi,
      i searched the forum to communicate with a logitech G600 without using Shortcuts or Default Mouse Keys.
      the code below lets u use your sidekeys whenever you press down the ring key.
      before using the code you will have to unassign the keys in the logitech mouse driver software.
      The source of my code is a wacom usb script, wich was heavily modified to work.
      you might find some parts wierd, thats because this is my first attempt to communicate via raw hid. 
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <APISysConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIGdi.au3> #include <WinAPIMisc.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> #cs ; #include "CommMG.au3" $mgdebug = True Global $sportSetError $tset = _ComGetPortNames() for $i = 0 to UBound($tset) -1 if $tset[$i][1] = "Serielles USB-Gerät" Then $COMPort = StringTrimLeft($tset[$i][0],3) ConsoleWrite("Teensy an Port COM" & $COMPort & " gefunden!" & @CRLF) EndIf Next $resOpen = _CommSetPort($COMPort,$sportSetError,31250, 8,0,1,0,0,0) if $resOpen = 0 then ConsoleWrite($sportSetError & @LF) ;~ Exit EndIf #ce $atagRID_DEVICE_INFO_HID = 'struct;dword VendorId;dword ProductId;dword VersionNumber;ushort UsagePage;ushort Usage;endstruct' $atagRID_INFO_HID = 'dword Size;dword Type;' & $atagRID_DEVICE_INFO_HID & ';dword Unused[2]' Opt('TrayAutoPause', 0) ; Create GUI Global $g_hForm = GUICreate('G600', 100, 25, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) Local $tRID = DllStructCreate($tagRAWINPUTDEVICE) DllStructSetData($tRID, 'Flags', $RIDEV_INPUTSINK) DllStructSetData($tRID, 'hTarget', $g_hForm) DllStructSetData($tRID, 'UsagePage', 0x80) ; Logitech G600 DllStructSetData($tRID, 'Usage', 0x0A) ; _WinAPI_RegisterRawInputDevices($tRID) ; Now iterate to find other devices Local $tText, $aData = _WinAPI_EnumRawInputDevices() If IsArray($aData) Then ReDim $aData[$aData[0][0] + 1][3] $tText = DllStructCreate('wchar[256]') For $i = 1 To $aData[0][0] If _WinAPI_GetRawInputDeviceInfo($aData[$i][0], $tText, 256, $RIDI_DEVICENAME) Then $aData[$i][2] = DllStructGetData($tText, 1) Else $aData[$i][2] = '' EndIf If $aData[$i][1] = $RIM_TYPEHID Then $devInf = DllStructCreate($atagRID_INFO_HID) If _WinAPI_GetRawInputDeviceInfo($aData[$i][0], $devInf, DllStructGetSize($devInf), $RIDI_DEVICEINFO ) Then If DllStructGetData($devInf, 'VendorId') = 0x046D And DllStructGetData($devInf, 'ProductId') = 0xC24A then ; G600 VID & PID ConsoleWrite ("Device Info:-" & @CRLF) ConsoleWrite ('VendorId: ' & Hex(DllStructGetData($devInf, 'VendorId'),4) & @CRLF) ConsoleWrite ('ProductId: ' & Hex(DllStructGetData($devInf, 'ProductId'),4) & @CRLF) ConsoleWrite ('VersionNumber: ' & DllStructGetData($devInf, 'VersionNumber') & @CRLF) ConsoleWrite ('UsagePage: ' & Hex(DllStructGetData($devInf, 'UsagePage'),2) & @CRLF) ConsoleWrite ('Usage: ' & Hex(DllStructGetData($devInf, 'Usage'),2) & @CRLF) DllStructSetData($tRID, 'UsagePage', DllStructGetData($devInf, 'UsagePage')) DllStructSetData($tRID, 'Usage', DllStructGetData($devInf, 'Usage')) _WinAPI_RegisterRawInputDevices($tRID) EndIf EndIf EndIf Next EndIf ; Register WM_INPUT message GUIRegisterMsg($WM_INPUT, 'WM_INPUT') GUISetState(@SW_SHOW) Global $structHID_DATA = "struct;" & _ "dword Type;" & _ "dword Size;" & _ "handle hDevice;" & _ "wparam wParam;" & _ "dword dwSizeHid;" & _ "dword dwCount;" & _ "endstruct;" Global $structWACOM_PEN_DATA = "struct;" & _ "dword Type;" & _ "dword Size;" & _ "handle hDevice;" & _ "wparam wParam;" & _ "dword dwSizeHid;" & _ "dword dwCount;" & _ "ubyte bRawData00;" & _ "ubyte penvsEraser;" & _ "word x;" & _ "word y;" & _ "word proximity;" & _ "word pressure;" & _ "ubyte bRawData09;" & _ "ubyte bRawData10;" & _ "ubyte bRawData11;" & _ "ubyte bRawData12;" & _ "ubyte bRawData13;" & _ "ubyte bRawData14;" & _ "ubyte bRawData15;" & _ "ubyte bRawData16;" & _ "ubyte bRawData17;" & _ "ubyte bRawData18;" & _ "ubyte bRawData19;" & _ "ubyte bRawData20;" & _ "ubyte bRawData21;" & _ "ubyte bRawData22;" & _ "ubyte bRawData23;" & _ "ubyte bRawData24;" & _ "ubyte bRawData25;" & _ "ubyte bRawData26;" & _ "ubyte bRawData27;" & _ "ubyte bRawData28;" & _ "ubyte bRawData29;" & _ "ubyte bRawData30;" & _ "ubyte bRawData31;" & _ "ubyte bRawData32;" & _ "ubyte bRawData33;" & _ "ubyte tilt_ba;" & _ "ubyte bRawData35;" & _ "ubyte tilt_na;" & _ "ubyte bRawData37;" & _ "endstruct;" Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam Switch $hWnd Case $g_hForm Local $tRIM = DllStructCreate($tagRAWINPUTHEADER) If _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_HEADER) Then ; Retrieves the raw input from the specified device $devType = DllStructGetData($tRIM, 'Type') $devSize = DllStructGetData($tRIM, 'Size') Else ConsoleWrite ("Device Header Retrieval Failed" & @CRLF) Return EndIf ; Now use the handle to the device to get it's name Local $tText = DllStructCreate('wchar[256]') If _WinAPI_GetRawInputDeviceInfo(DllStructGetData($tRIM, 'hDevice'), $tText, 256, $RIDI_DEVICENAME) Then $devName = DllStructGetData($tText, 1) Else ConsoleWrite ("Device Name Retrieval Failed" & @CRLF) EndIf if $devType = $RIM_TYPEHID Then $tRIM = DllStructCreate($structWACOM_PEN_DATA) If _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_INPUT) Then if DllStructGetData($tRIM, 8) = 32 Then ; filter for ring key down (G-Mode) Switch DllStructGetData($tRIM, 9) ; if in g mode assign the Keys G9 to G20 to autoit functions. case 0 Return ; key released case 1 g1() case 2 g2() case 4 g3() case 8 g4() case 16 g5() case 32 g6() case 64 g7() case 128 g8() case 256 g9() case 512 g10() case 1024 g11() case 2048 g12() Case Else ;;; ConsoleWrite(DllStructGetData($tRIM, 9) & @CRLF) EndSwitch EndIf EndIf EndIf EndSwitch sleep(50) Return $GUI_RUNDEFMSG EndFunc ;==>WM_INPUT Func g1() ;~ Send("2") ConsoleWrite("g1" & @CRLF) ;~ _CommSendString("KEY_TAB" & @LF) ;~ Sleep(random(50,100,1)) ;~ _CommSendString("KEY_RELEASE_ALL" & @LF) ;~ Sleep(random(50,100,1)) ;~ _CommSendString("KEY_2" & @LF) ;~ Sleep(random(50,100,1)) ;~ _CommSendString("KEY_RELEASE_ALL" & @LF) EndFunc Func g2() ConsoleWrite("g2" & @CRLF) EndFunc Func g3() ConsoleWrite("g3" & @CRLF) EndFunc Func g4() ConsoleWrite("g4" & @CRLF) EndFunc Func g5() ConsoleWrite("g5" & @CRLF) EndFunc Func g6() ConsoleWrite("g6" & @CRLF) EndFunc Func g7() ConsoleWrite("g7" & @CRLF) EndFunc Func g8() ConsoleWrite("g8" & @CRLF) EndFunc Func g9() ConsoleWrite("g9" & @CRLF) EndFunc Func g10() ConsoleWrite("g10" & @CRLF) EndFunc Func g11() ConsoleWrite("g11" & @CRLF) EndFunc Func g12() ConsoleWrite("g12" & @CRLF) EndFunc  
    • nacerbaaziz
      By nacerbaaziz
      Hi all
      I want a way to get the last key pressed.
      I have a program that works with keyboard shortcuts and I want to  give the permission for the user to edit shortcut keys depending on what suits him
      i  want to make read-only edit box and the program writes the latest shortcut key pressed
      Please help me,
      greetings to all
      And thanks in advance
    • JustinZandee
      By JustinZandee
      I want to create a loop which loops a code until for example f2 is pressed.
      So I tried something with _IsPressed but it doesn't work.
      Local $test = WinActivate("Notepad") Do Send("hi") Until _IsPressed("72", $test)  
      I don't know how I can do nothing when pressing f2 because it says "error: _IsPressed(): undefined function.".
      I did put 
      Send("hi") after Local $test = but it gives the same error.
      Does anyone know how to solve this problem? 
      Maybe I am wrong and I need to use a whole other Function.. I am new to AutoIT so I am sorry..
       
×