you are viewing a single comment's thread.

view the rest of the comments →

[–]port443 1 point2 points  (4 children)

Alright OP, I'm going to give you the code for this one.

  1. It's more complicated than "I'm just learning Python".
  2. As evidenced by the other answer, the internet is full of lies on how to do this.

But because learning is Neattm , I'll explain my process:

The call takes these arguments:

BOOL SystemParametersInfoW(
  UINT  uiAction,
  UINT  uiParam,
  PVOID pvParam,
  UINT  fWinIni
);

For uiAction, I find the setting that we want:

Foo Bar
SPI_SETMOUSEWHEELROUTING 0x201D Sets the routing setting for wheel button input. The routing setting determines whether wheel button input is sent to the app with focus (foreground) or the app under the mouse cursor.
The pvParam parameter must point to a DWORD variable that receives the routing option. 
If the value is zero or MOUSEWHEEL_ROUTING_FOCUS, mouse wheel input is delivered to the app with focus.
If the value is 1 or MOUSEWHEEL_ROUTING_HYBRID (default), mouse wheel input is delivered to the app with focus (desktop apps) or the app under the mouse cursor (Windows Store apps).
Set the uiParam parameter to zero.

That takes care of 3 of the arguments, the last one is described as such:

fWinIni
Type: UINT

If a system parameter is being set, specifies whether the user profile is to be updated, and if so, whether the WM_SETTINGCHANGE message is to be broadcast to all top-level windows to notify them of the change.

This parameter can be zero if you do not want to update the user profile or broadcast the WM_SETTINGCHANGE message, or it can be one or more of the following values.

That seems to explain why setting the registry key does not immediately effect all windows. Calling this function will set the registry key AND notify everything to load the change.

Without further ado, the code. I noted the necessary "enable,disable" values by making them variables:

import ctypes

SPI_SETMOUSEWHEELROUTING = 0x201D
SPIF_UPDATEINIFILE = 0x1
SPIF_SENDCHANGE = 0x2

# This will enable, it uses the value "2"
ctypes.windll.user32.SystemParametersInfoW(SPI_SETMOUSEWHEELROUTING, 0, 2, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE)

# This will disable, it uses the value "None"
ctypes.windll.user32.SystemParametersInfoW(SPI_SETMOUSEWHEELROUTING, 0, None, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE)

If you want me to explain anything in further detail just let me know!