將鼠標光標移動到Lubuntu中的特定位置(熱角)時執行操作


4

是否可以配置Lubuntu(即Openbox),以便在將鼠標光標移至某個位置時執行某些操作?

尤其是,當我將鼠標光標移到左上角並繼續向上和向左推時,我想運行一個腳本。這類似於某些窗口管理器,當您將鼠標光標推到屏幕的任一側時,這些窗口管理器使您可以切換到另一個顯示。

4

One way to accomplish this is via xdotool. From xdotool's manual:

behave_screen_edge [options] where command ...

Bind an action to events when the mouse hits the screen edge or corner.

Options are:

--delay MILLISECONDS

Delay in milliseconds before running the command. This allows you to require a given edge or corner to be held for a short period before your command will run. If you leave the edge or corner before the delay expires then the time will reset.

--quiesce MILLISECONDS

Delay in milliseconds before the next command will run. This helps prevent accidentally running your command extra times; especially useful if you have a very short --delay (like the default of 0).

Event timeline

  • Mouse hits an edge or corner.
  • If delay is nonzero, the mouse must stay in this edge or corner until delay time expires.
  • If still in the edge/corner, trigger.
  • If quiesce is nonzero, then there is a cool-down period where the next trigger cannot occur

Valid 'where' values are:

  • left

  • top-left

  • top

  • top-right

  • right

  • bottom-left

  • bottom

  • bottom-right

You can combine the behave_screen_edge option with any of xdotool's inbuilt commands, including the exec command:

exec [options] command [...]

Execute a program. This is often useful when combined with behave_screen_edge to do things like locking your screen.

Options:

--sync

Block until the child process exits. The child process exit status is then passed to the parent process (xdotool) which copies it.


So to trigger a script when hitting the top left corner of your screen you would use the following command:

xdotool behave_screen_edge top-left exec --sync script.sh

The --sync switch ensures that xdotool waits until the script exits before triggering the action again.


xdotool is part of the official Ubuntu repositories and may be installed via:

sudo apt-get install xdotool