Skip to content

Instantly share code, notes, and snippets.

@soda92
Created November 28, 2024 09:47
Show Gist options
  • Save soda92/f84a2de842d3e525717478d03ee61acb to your computer and use it in GitHub Desktop.
Save soda92/f84a2de842d3e525717478d03ee61acb to your computer and use it in GitHub Desktop.
convert mouse cursor image to left-handed (horizontally flip) using python

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)

2. 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.

3. 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)

4. 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

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