All of it is a bullshit code all around. Are you guys really don't have no problems with an XAUTHORITY and DISPLAY? I don't believe that. So here's the really working solution (remember to replace $USER with your username):
step 1. Generate your ".Xmodmap" file with the mapping, in my case it is:
keycode 96 = XF86AudioLowerVolume
keycode 95 = XF86AudioMute
keycode 76 = XF86AudioNext
keycode 75 = XF86AudioPlay
keycode 74 = XF86AudioPrev
and place it under /home/$USER/.Xmodmap path
step 2. Create a startup application preference (go to Startup Application Preferences from super-button search menu) and add the following:
Name: xmodmap
Command: /bin/bash -c "sleep 7 && xmodmap ~/.Xmodmap"
Comment:
and Save it. And close the Startup Application Preferences
step 3. now go to /usr/lib/systemd/system-sleep folder, like this:
cd /usr/lib/systemd/system-sleep
step 4. create a file named "xkeyboard.sh", you can do it like this (sudo rights are required):
sudo touch xkeyboard.sh
step 5. now get your $XAUTHORITY variable value, you can do it like this:
echo $XAUTHORITY
in my case it returned me the following:
/run/user/1000/gdm/Xauthority
write it down somewhere
step 6. open up your newely created file for editing, you can do it like this:
sudo nano xkeyboard.sh
step 7: paste this code. Make sure to replace $USER with your username and $XAUTH with the variable you wrote down before:
#!/bin/bash
echo "Running xkeyboard.sh with argument: $1" >> /tmp/xkeyboard.log
if [ "${1}" == "pre" ]; then
echo "pre" >> /tmp/xkeyboard.log
# Nothing to do for pre-sleep
elif [ "${1}" == "post" ]; then
echo "post" >> /tmp/xkeyboard.log
export DISPLAY=:0 # Set the DISPLAY variable
export XAUTHORITY=$XAUTH
/bin/bash -c "sleep 7 && xmodmap home/$USER/.Xmodmap" >> /tmp/xkeyboard.log 2>&1
fi
in this code i've added up logging to /tmp/xkeyboard.log file, so if keyboard mapping doesn't work, you can go there and checkout what's the matter.