Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created June 17, 2020 10:27
Show Gist options
  • Save jstangroome/eec58484f8060b44ecc23d383ad22d94 to your computer and use it in GitHub Desktop.
Save jstangroome/eec58484f8060b44ecc23d383ad22d94 to your computer and use it in GitHub Desktop.
Change the mouse drag distance required to initiate a drag operation, e.g. moving files in Explorer
param (
[int]$drag = 4
)
# https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa
$importDefinition= @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
'@
$importType = Add-Type -MemberDefinition $importDefinition -Name WinAPICall -Namespace SetDragSystemParametersInfo –PassThru
$SPI_SETDRAGWIDTH=0x004C
$SPI_SETDRAGHEIGHT=0x004D
$SPIF_UPDATEINIFILE = 0x1 # persist the change between login sessions (not actually via .ini file)
$SPIF_SENDCHANGE = 0x2 # apply the change to the current session without logging out, and back in.
$importType::SystemParametersInfo($SPI_SETDRAGWIDTH, $drag, $null, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
$importType::SystemParametersInfo($SPI_SETDRAGHEIGHT, $drag, $null, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
@LesFerch
Copy link

LesFerch commented Nov 6, 2023

The posted code got corrupted somewhere along the way.
–PassThru should be -PassThru
The former string has a Unicode hyphen which will cause an error that displays as –PassThru

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment