ฉันใช้บรรทัดต่อไปนี้ในไฟล์ ~/.xprofile
บน Ubuntu 20.04 เพื่อแมป แคปล็อค ถึง เอสซี และ Ctrl:
# ทำให้ CapsLock ทำงานเหมือน Ctrl:
setxkbmap - ตัวเลือก ctrl:nocaps
# ทำให้ Ctrl ที่กดสั้น ๆ ทำงานเหมือน Escape:
xcape -e 'Control_L=Escape'
ซึ่งใช้งานได้ดีสำหรับฉัน
ปัญหาของฉันคือไม่สามารถระงับ/ดำเนินการต่อได้อย่างน่าเชื่อถือสำหรับสิ่งนี้ ฉันได้ลองใช้วิธีแก้ปัญหาที่แตกต่างกัน 2 วิธี:
1. ผ่านสคริปต์ แคปแมป
ใส่เข้าไป /usr/lib/systemd/system-sleep/
#!/bin/bash
กรณี "$1" ใน
ก่อน)
#codeexecution ก่อน sleep/hibernate/suspending
;;
โพสต์)
การดำเนินการ #code หลังจากดำเนินการต่อ
/usr/bin/echo "ดำเนินการ: /usr/bin/setxkbmap -option ctrl:nocaps"
/usr/bin/setxkbmap - ตัวเลือก ctrl:nocaps
/usr/bin/echo "ดำเนินการ: /usr/bin/xcape -e 'Control_L=Escape'"
/usr/bin/xcape -e 'Control_L=Escape'
;;
เอสแซค
ทางออก 0
ฉันทำให้สคริปต์สามารถเรียกใช้งานได้ด้วย sudo chmod +x แคปแมป
และดูได้จากบันทึกว่าถูกเรียกใช้ในเวลาที่เหมาะสม:
$ วารสาร ctl
...
Okt 09 13:29:12 nb systemd-sleep[401221]: ระบบกลับมาทำงานต่อ
Okt 09 13:29:12 เคอร์เนล nb: Bluetooth: hci0: การแก้ไขอุปกรณ์คือ 5
Okt 09 13:29:12 เคอร์เนล nb: Bluetooth: hci0: เปิดใช้งานการบูตแบบปลอดภัย
Okt 09 13:29:12 เคอร์เนล nb: Bluetooth: hci0: เปิดใช้งานการล็อค OTP
Okt 09 13:29:12 เคอร์เนล nb: Bluetooth: hci0: เปิดใช้งานการล็อค API
Okt 09 13:29:12 เคอร์เนล nb: Bluetooth: hci0: ปิดใช้งานการล็อกการดีบัก
Okt 09 13:29:12 เคอร์เนล nb: Bluetooth: hci0: สร้างเฟิร์มแวร์ขั้นต่ำ 1 สัปดาห์ 10 2014
Okt 09 13:29:12 เคอร์เนล nb: บลูทูธ: hci0: พบเฟิร์มแวร์อุปกรณ์: intel/ibt-11-5.sfi
09 ตุลาคม 13:29:12 nb systemd-sleep [401287]: ดำเนินการ: /usr/bin/setxkbmap -option ctrl:nocaps
Okt 09 13:29:12 nb systemd-sleep [401288]: ไม่สามารถเปิดจอแสดงผล "จอแสดงผลเริ่มต้น"
09 ตุลาคม 13:29:12 nb systemd-sleep[401291]: ดำเนินการ: /usr/bin/xcape -e 'Control_L=Escape'
Okt 09 13:29:12 nb systemd-sleep[401293]: ไม่สามารถเชื่อมต่อกับจอแสดงผล X11 $DISPLAY ตั้งค่าไว้หรือไม่
09 ตุลาคม 13:29:12 nb systemd[1]: systemd-suspend.service: สำเร็จ
Okt 09 13:29:12 nb systemd[1]: เสร็จสิ้นการระงับ
Okt 09 13:29:12 nb systemd[1]: หยุดเป้าหมาย Sleep
09 ตุลาคม 13:29:12 nb systemd[1]: บรรลุเป้าหมาย Suspend
09 ตุลาคม 13:29:12 nb systemd[1]: หยุดเป้าหมาย ระงับ
...
อย่างไรก็ตาม การแมปจะใช้ได้ในบางครั้งเท่านั้น ค่อนข้างบ่อย, แคปล็อค เพียงแค่ทำตัวตามปกติ
2. ผ่านบริการ systemd
ฉันได้เพิ่มไฟล์บริการแล้ว capsmap.service
ถึง ฯลฯ/systemd/ระบบ/
โดยมีเนื้อหาดังนี้
[หน่วย]
คำอธิบาย=แมป Capslock กับ ESC และ Ctrl
After=suspend.target
[บริการ]
Type=วันช็อต
ExecStart=/usr/local/bin/capsmap
หมดเวลาวินาที=0
StandardOutput=syslog
[ติดตั้ง]
WantedBy=multi-user.target suspend.target
ด้วยไฟล์ /usr/local/bin/capsmap
เช่น
#!/bin/bash
# ทำให้ CapsLock ทำงานเหมือน Ctrl:
/usr/bin/echo "ดำเนินการ: /usr/bin/setxkbmap -option ctrl:nocaps"
/usr/bin/setxkbmap - ตัวเลือก ctrl:nocaps
# ทำให้ Ctrl ที่กดสั้น ๆ ทำงานเหมือน Escape:
/usr/bin/echo "ดำเนินการ: /usr/bin/xcape -e 'Control_L=Escape'"
/usr/bin/xcape -e 'Control_L=Escape'
ทางออก 0
แล้วเปิดใช้บริการกับ sudo systemctl เปิดใช้งาน capsmap.service
.
นอกจากนี้ในกรณีนี้ฉันสามารถเห็นได้ด้วย วารสาร ctl
ว่าสคริปต์ถูกเรียกใช้งานสำเร็จแต่เป็นปกติ แคปล็อค พฤติกรรมยังคงอยู่
$journalctl
...
09 ตุลาคม 13:07:56 nb systemd[1]: หยุดเป้าหมาย ระงับ
Okt 09 13:07:56 nb NetworkManager[1049]: <info> [1633777676.0331] ผู้จัดการ: สลีป: ร้องขอการปลุก (สลีป: ใช่ เปิดใช้งาน: ใช่)
09 ตุลาคม 13:07:56 nb ModemManager[1137]: ระบบ <info> [sleep-monitor] กำลังดำเนินการต่อ
09 ตุลาคม 13:07:56 nb NetworkManager[1049]: <info> [1633777676.0332] อุปกรณ์ (enp0s31f6): การเปลี่ยนสถานะ: เปิดใช้งาน -> ไม่มีการจัดการ (เหตุผล 'นอนหลับ', sys-iface-state: 'จัดการ')
Okt 09 13:07:56 nb systemd[1761]: หยุดเป้าหมาย Bluetooth
Okt 09 13:07:56 nb uppowerd[1344]: การรักษาเหตุการณ์การเปลี่ยนแปลงเป็นส่วนเสริม /sys/devices/pci0000:00/0000:00:14.0/usb1/1-8
09 ตุลาคม 13:07:56 nb capsmap [378798]: ดำเนินการ: /usr/bin/setxkbmap -option ctrl:nocaps
Okt 09 13:07:56 nb systemd[1761]: ถึงเป้าหมาย Bluetooth แล้ว
09 ตุลาคม 13:07:56 nb NetworkManager[1049]: <info> [1633777676.0498] dhcp4 (enp0s31f6): ยกเลิกธุรกรรม DHCP
Okt 09 13:07:56 nb capsmap[378799]: ไม่สามารถเปิดจอแสดงผล "จอแสดงผลเริ่มต้น"
Okt 09 13:07:56 nb NetworkManager[1049]: <info> [1633777676.0498] dhcp4 (enp0s31f6): สถานะเปลี่ยนขอบเขต -> เสร็จสิ้น
09 ตุลาคม 13:07:56 nb avahi-daemon[1041]: การถอนบันทึกที่อยู่สำหรับ 192.168.178.54 บน enp0s31f6
09 ตุลาคม 13:07:56 nb avahi-daemon[1041]: ออกจากกลุ่มมัลติคาสต์ mDNS บนอินเทอร์เฟซ enp0s31f6.IPv4 พร้อมที่อยู่ 192.168.178.54
09 ตุลาคม 13:07:56 nb avahi-daemon[1041]: อินเทอร์เฟซ enp0s31f6.IPv4 ไม่เกี่ยวข้องกับ mDNS อีกต่อไป
09 ตุลาคม 13:07:56 nb avahi-daemon[1041]: การถอนบันทึกที่อยู่สำหรับ fe80::778b:d324:d55d:a503 บน enp0s31f6
09 ตุลาคม 13:07:56 nb avahi-daemon[1041]: ออกจากกลุ่มมัลติคาสต์ mDNS บนอินเทอร์เฟซ enp0s31f6.IPv6 พร้อมที่อยู่ fe80::778b:d324:d55d:a503
09 ตุลาคม 13:07:56 nb avahi-daemon[1041]: อินเทอร์เฟซ enp0s31f6.IPv6 ไม่เกี่ยวข้องกับ mDNS อีกต่อไป
Okt 09 13:07:56 nb systemd[1]: เริ่มโหลด/บันทึก RF Kill Switch Status
09 ตุลาคม 13:07:56 nb capsmap [378800]: ดำเนินการ: /usr/bin/xcape -e 'Control_L=Escape'
09 ตุลาคม 13:07:56 nb NetworkManager[1049]: <info> [1633777676.0545] ผู้จัดการ: สถานะ NetworkManager คือ CONNECTED_GLOBAL
Okt 09 13:07:56 nb capsmap[378805]: ไม่สามารถเชื่อมต่อกับจอแสดงผล X11 $DISPLAY ตั้งค่าไว้หรือไม่
09 ตุลาคม 13:07:56 เคอร์เนล nb: kauditd_printk_skb: 9 การโทรกลับถูกระงับ
09 ตุลาคม 13:07:56 เคอร์เนล nb: การตรวจสอบ: type=1107 การตรวจสอบ (1633777676.068:1737): pid=1047 uid=103 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_signal" รถบัส = "ระบบ" เส้นทาง = "/org/freedesktop/NetworkManager/ActiveConnection/30" interface = "org.fr>
exe="/usr/bin/dbus-daemon" sauid=103 ชื่อโฮสต์=? แอดเดอร์=? เทอร์มินัล=?'
09 ตุลาคม 13:07:56 เคอร์เนล nb: การตรวจสอบ: type=1107 การตรวจสอบ (1633777676.068:1738): pid=1047 uid=103 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_signal" รถบัส = "ระบบ" เส้นทาง = "/org/freedesktop/NetworkManager/ActiveConnection/30" interface = "org.fr>
exe="/usr/bin/dbus-daemon" sauid=103 ชื่อโฮสต์=? แอดเดอร์=? เทอร์มินัล=?'
09 ตุลาคม 13:07:56 nb การตรวจสอบ [1047]: USER_AVC pid=1047 uid=103 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_signal" bus="system" path=" /org/freedesktop/NetworkManager/ActiveConnection/30" interface="org.freedesktop.NetworkManager.Connec>
exe="/usr/bin/dbus-daemon" sauid=103 ชื่อโฮสต์=? แอดเดอร์=? เทอร์มินัล=?'
09 ตุลาคม 13:07:56 nb การตรวจสอบ [1047]: USER_AVC pid=1047 uid=103 auid=4294967295 ses=4294967295 subj=unconfined msg='apparmor="DENIED" operation="dbus_signal" bus="system" path=" /org/freedesktop/NetworkManager/ActiveConnection/30" interface="org.freedesktop.NetworkManager.Connec>
exe="/usr/bin/dbus-daemon" sauid=103 ชื่อโฮสต์=? แอดเดอร์=? เทอร์มินัล=?'
Okt 09 13:07:56 nb systemd[1]: capsmap.service: สำเร็จ
...