how do you listen for mediakey events under gnome 3 using python?

  • Last Update :
  • Techknowledgy :

The questioner said this code works:

#!/usr/bin/env python

""
"Printing out gnome multi media keys via dbus-python.
""
"
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib

def on_mediakey(comes_from, what):
   ""
" gets called when multimedia keys are pressed down.
""
"
print('comes from:%s  what:%s') % (comes_from, what)
if what in ['Stop', 'Play', 'Next', 'Previous']:
   print('Got a multimedia key!')
else:
   print('Got a multimedia key...')

# set up the glib main loop.
dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
bus_object = bus.get_object('org.gnome.SettingsDaemon',
   '/org/gnome/SettingsDaemon/MediaKeys')

# this is what gives us the multi media keys.
dbus_interface = 'org.gnome.SettingsDaemon.MediaKeys'
bus_object.GrabMediaPlayerKeys("MyMultimediaThingy", 0,
   dbus_interface = dbus_interface)

# connect_to_signal registers our callback
function.
bus_object.connect_to_signal('MediaPlayerKeyPressed',
   on_mediakey)

# and we start the main loop.
mainloop = gobject.MainLoop()
mainloop.run()

Suggestion : 2

This page was last edited on 20 June 2022, at 23:24.

The traditional way to get a scancode is to use the showkey(1) utility. showkey waits for a key to be pressed, or exits if no keys are pressed within 10 seconds. For showkey to work you need to be in a virtual console, not in a graphical environment or logged in via a network connection. Run the following command:

# showkey--scancodes

For USB keyboards, it is apparently necessary to use evtest(1) from the evtest package instead of showkey [1]:

# evtest / dev / input / event12
# evtest /dev/input/event12
...
Event: time 1434666536.001123, type 4(EV_MSC), code 4(MSC_SCAN), value 70053
Event: time 1434666536.001123, type 1(EV_KEY), code 69(KEY_NUMLOCK), value 0
Event: time 1434666536.001123, -- -- -- -- -- -- --EV_SYN-- -- -- -- -- --

The keycodes for virtual console are reported by the showkey(1) utility. showkey waits for a key to be pressed and if none are, in a span of 10 seconds, it quits. To execute showkey, you need to be in a virtual console, not in a graphical environment. Run the following command:

# showkey--keycodes

With the following command you can start xev and show only the relevant parts:

$ xev | awk - F '[ )]+'
'/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'

Suggestion : 3

Apart from high-level options, it’s possible to tweak a package in almost arbitrary ways, such as changing or disabling dependencies of a package. For instance, the Emacs package in Nixpkgs by default has a dependency on GTK 2. If you want to build it against GTK 3, you can specify that as follows: , The second possibility is to add the package outside of the Nixpkgs tree. For instance, here is how you specify a build of the GNU Hello package directly in configuration.nix: , Once you are done making modifications to the manual, it's important to build it before committing. You can do that as follows: , With declarative package management, you specify which packages you want on your system by setting the option environment.systemPackages. For instance, adding the following line to configuration.nix enables the Mozilla Thunderbird email application:

You are logged-in automatically as nixos. The nixos user account has an empty password so you can use sudo without a password:

$ sudo - i

On the minimal installer, NetworkManager is not available, so configuration must be perfomed manually. To configure the wifi, first start wpa_supplicant with sudo systemctl start wpa_supplicant, then run wpa_cli. For most home networks, you need to type in the following commands:

> add_network
0
   >
   set_network 0 ssid "myhomenetwork"
OK
   >
   set_network 0 psk "mypassword"
OK
   >
   set_network 0 key_mgmt WPA - PSK
OK
   >
   enable_network 0
OK

For enterprise networks, for example eduroam, instead do:

> add_network
0
   >
   set_network 0 ssid "eduroam"
OK
   >
   set_network 0 identity "myname@example.com"
OK
   >
   set_network 0 password "mypassword"
OK
   >
   set_network 0 key_mgmt WPA - EAP
OK
   >
   enable_network 0
OK

On the minimal installer, NetworkManager is not available, so configuration must be perfomed manually. To configure the wifi, first start wpa_supplicant with sudo systemctl start wpa_supplicant, then run wpa_cli. For most home networks, you need to type in the following commands:

> add_network
0
   >
   set_network 0 ssid "myhomenetwork"
OK
   >
   set_network 0 psk "mypassword"
OK
   >
   set_network 0 key_mgmt WPA - PSK
OK
   >
   enable_network 0
OK

For enterprise networks, for example eduroam, instead do:

> add_network
0
   >
   set_network 0 ssid "eduroam"
OK
   >
   set_network 0 identity "myname@example.com"
OK
   >
   set_network 0 password "mypassword"
OK
   >
   set_network 0 key_mgmt WPA - EAP
OK
   >
   enable_network 0
OK

When successfully connected, you should see a line such as this one

< 3 > CTRL - EVENT - CONNECTED - Connection to 32: 85: ab: ef: 24: 5 c completed[id = 0 id_str = ]

Create a GPT partition table.

# parted / dev / sda--mklabel gpt

Add the root partition. This will fill the disk except for the end part, where the swap will live, and the space left in front (512MiB) which will be used by the boot partition.

# parted / dev / sda--mkpart primary 512 MiB - 8 GiB

Next, add a swap partition. The size required will vary according to needs, here a 8GiB one is created.

# parted / dev / sda--mkpart primary linux - swap - 8 GiB 100 %

Finally, the boot partition. NixOS by default uses the ESP (EFI system partition) as its /boot partition. It uses the initially reserved 512MiB at the start of the disk.

# parted / dev / sda--mkpart ESP fat32 1 MiB 512 MiB
# parted / dev / sda--set 3 esp on