Skip to content

Instantly share code, notes, and snippets.

@soda92
Created October 10, 2024 14:02
Show Gist options
  • Save soda92/30cf432918034c40e2f6eb31b115f2f6 to your computer and use it in GitHub Desktop.
Save soda92/30cf432918034c40e2f6eb31b115f2f6 to your computer and use it in GitHub Desktop.
convert mouse cursor image to left-handed (horizontally flip) using python

Recently I find that Windows mouse cursor is not very friently for left-handed people. Because it point from right to left.

So I wonder if there is a way to change it to "left to right". I searched the internet but havnen't found one.

Further search give me a message that the "cur" file format is a derivation of the "ico" format: https://en.wikipedia.org/wiki/ICO_(file_format)

So I think if we can flip it programatically.

Currently I can use these steps to modify one image:

  1. Copy C:\Windows\Cursors to a directory, then use the following script to convert to "ico" files so GIMP can recognize it
from pathlib import Path

CURRENT = Path(__file__).resolve().parent

CURRENT.joinpath("Cursors_ico").mkdir(exist_ok=True)
files = list(CURRENT.joinpath("Cursors").glob("*.cur"))

for file in files:
    dest = CURRENT.joinpath("Cursors_ico")
    data = file.read_bytes()
    data = bytearray(data)
    data[2] = 0x01
    dest.joinpath(file.stem + ".ico").write_bytes(data)
  1. use GIMP to flip this step isn't very intresting. I will have to delete all other layers, and use selection to select the cursor, and use "Layer -> Transform -> Flip horizontally". Then export ico file. Also the hotspot location has changed so we need to remember its location.

  2. convert back to "cur" file script:

from pathlib import Path

file = Path("aero_link.ico")
data = bytearray(file.read_bytes())
data[10] = 102 # hover on the finger and you can see the location in the GIMP bottom pane. fill it here
data[2] = 0x02 # change the file header back

Path("aero_link.cur").write_bytes(data)
  1. Load file In settings - bluetooth & devices - mouse - additional mouse settings - pointers, create a new scheme, and change the "link select" image

I wonder if we can do the step 2 automatically

@soda92
Copy link
Author

soda92 commented Oct 10, 2024

Also there is a display bug for Microsoft Windows's Window manager:
if you move cursor to top-left corner, it will cause the screen goes black, plus taskbar and video playback issues

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