Print at Dec 16, 2025, 12:32:03 PM

Posted by klaus0 at Jan 27, 2025, 12:02:46 PM
Re: customize function keys in windows to make keyboard shortcuts
If someone else comes across this: I solved it by writing a small bash script.

Requirements: Git for Windows, to be executed by "Git Bash". With default install location of Sweet Home 3D, has to be run in a shell that has been opened with admin permissions.

Modification: Adjust the variables at the beginning of the file. Should be self-explanatory.

The script:


#!/usr/bin/bash
# -*- coding: utf-8-unix -*-
# shellcheck enable=check-unassigned-uppercase
# shellcheck disable=SC2064

set -e -u


INSTALL_DIR="C:/Program Files (x86)/Sweet Home 3D"
JAR_FILE="${INSTALL_DIR}/lib/SweetHome3D.jar"
PACKAGE_FILE="com/eteks/sweethome3d/swing/package.properties"
KEY_OVERRIDES=(
E HomePane.MODIFY_ROOM
E HomePane.MODIFY_FURNITURE
E HomePane.MODIFY_WALL
E HomePane.MODIFY_DIMENSION_LINE
E HomePane.MODIFY
"control J" HomePane.JOIN_WALLS
ESCAPE HomePane.SELECT
L HomePane.CREATE_DIMENSIONS
J HomePane.CREATE_POLYLINES
T HomePane.CREATE_LABELS
W HomePane.CREATE_WALLS
R HomePane.CREATE_ROOMS
)

# back up the original file as a starting point
if ! [[ -e "${JAR_FILE}.bak" ]]; then
cp "${JAR_FILE}" "${JAR_FILE}.bak"
fi

# set up a temporary directory
TMPDIR=$(mktemp -d)
trap "rm -rf '$TMPDIR'" exit
cd "$TMPDIR"

# extract the settings files

unzip "${JAR_FILE}.bak" "${PACKAGE_FILE}"

# list current hotkeys
echo
echo CURRENT HOTKEYS
printf "%15s %8s %-20s %s\n" PANE KEYS MODIFIERS ACTION
perl -ne '
if(/^(?<pane>.+?)\.(?<action>.+)\.AcceleratorKey=(?<modifiers>(\w+ )*)(?<key>\w+)$/) {
printf "%15s %8s %-20s %s\n", $+{pane}, $+{key}, $+{modifiers}, $+{action};
}
' "${PACKAGE_FILE}" | sort

# modify the file
echo
echo MODIFYING HOTKEYS...
i=0
cp "${PACKAGE_FILE}" "${PACKAGE_FILE}.old"
while [[ $i -lt ${#KEY_OVERRIDES[@]} ]]; do
key=${KEY_OVERRIDES[$((i++))]}
action=${KEY_OVERRIDES[$((i++))]}
perl -pe "s{^$action.AcceleratorKey=.*}{$action.AcceleratorKey=$key}" -i "${PACKAGE_FILE}"
done
diff -U0 "${PACKAGE_FILE}.old" "${PACKAGE_FILE}" || true

# updating jar file
echo
echo UPDATING JAR FILE...
zip "${JAR_FILE}" "${PACKAGE_FILE}"


echo
echo DONE...