The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Question about custom events

    Discussion in 'Linux Compatibility and Software' started by LostHero, Sep 23, 2010.

  1. LostHero

    LostHero Newbie

    Reputations:
    0
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    5
    A while back, I installed a keyboard backlight fix for Ubuntu from this site (I have an ASUS G73J that dual boots Windows 7 and Ubuntu 10.04). Today, I was trying to get the other hotkeys to work but had very little success.

    I ran into problems when trying to figure out how to identify the hotkey.
    For example, "event=hotkey (ATKD|HOTK) 0000002[0123456789abcdef]" activates when Fn+F3 are pressed but using showkey, I only get keycode 61 and scancode 0x3d. I also tried using xev and looking inside of kern.log but neither of them gave me readable results for what the hotkey was.
     
  2. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
  3. LostHero

    LostHero Newbie

    Reputations:
    0
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    5
    acpi_listen is exactly what I was looking for. Thank you.

    The following hotkeys don't do anything:
    Overdrive Button
    Fn-F8
    Fn-C
    Fn-V

    I might change some of the buttons so that they do different things than on Windows).

    Thanks again for your help.
     
  4. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    Yeah, you can bind the camera button in Gnome in System->Keyboard Shortcuts->Custom Shortcuts and Add one with whatever app you want to run.

    For monitoring the keys on the desktop layer you can use dbus-monitor, something like this:
    Code:
    sudo dbus-monitor --system | grep -i -A1 button
     
  5. LostHero

    LostHero Newbie

    Reputations:
    0
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    5
    Okay, thanks.

    After testing some of my hotkeys, I found out that my Fn-Enter (Calculator launcher) isn't associated with XF86-Calculator. Is there a way of fixing this?

    It turns out that Fn-C and the Screen Key are associated with XF86Launch1 so I can use the Keyboard Shortcuts menu on them (as well as on Fn-F8 and Fn-V). The only thing is that it is already programmed to turn off the touchpad. Is there a way of stopping this? Considering Fn-F9 already does this, I don't see any reason to double/triple up on it.

    So after assigning all the above keys using the Keyboard Shortcuts menu, I'll have roughly 2 keys that I will need t assign events to. The Overdrive button and the Lights button (I didn't think the OS was aware of this button until I used acpi_listen on it (sorta like the Fn key not having its own keycode)).
     
  6. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    8a is being picked up by asus-f8sv-touchpad, so just comment out the lines like this:
    Code:
    gksudo gedit /etc/acpi/events/asus-f8sv-touchpad
    Code:
    # /etc/acpi/events/asus-f8sv-touchpad
    # This is called when the user presses the touchpad button on the ASUS F8SV
    # and calls /etc/acpi/asus-touchpad.sh for further processing.
    
    #event=hotkey ATKD 0000008a
    #action=/etc/acpi/asus-touchpad.sh
    Then restart acpid:
    Code:
    sudo /etc/init.d/acpid restart
    Fn+Enter isn't 0x55 for you? You'd have to change it in the asus_laptop module, or make an acpi event and script with this line as the action:
    Code:
    acpi_fakekey $KEY_CALC
    See /etc/acpi/asus-brn-down.sh for an example of this, which is triggered by /etc/acpi/events/asus-brightness-down
     
  7. LostHero

    LostHero Newbie

    Reputations:
    0
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    5
    I'm sorry for the hassle but I ran into some more problems...

    Commenting out those lined fixed the touchpad problem but I'm running into problems with the Calculator fix. It works but then again, it doesn't. I always need to hit another button on the keyboard before the calculator will show up. The event and shell files look identical to your suggested examples (with the obvious exceptions of fakekey and hotkey ID).

    Also, I tried making another hotkey for Fn-Down so that it would start Rhythmbox (otherwise it would do its normal play/pause functions). After making the shell file executable, I was able to run it separately without any problems. Yet as soon as I try calling it by an acpi event, nothing happens. I double checked the hotkey ID. Heres what I got:

    /etc/acpi/events/music-player
    Code:
    event=hotkey (ATKD|HOTK) 00000045
    action=/etc/acpi/music-player.sh
    
    /etc/acpi/music-player.sh
    Code:
    #!/bin/sh
    
    #Starts Rhythmbox if it is not already running
    # Original/unnecessary coding:
    # ps -ef|grep -v grep|grep rhythmbox-client >/dev/null || rhythmbox-client
    
    rhythmbox-client
    
     
  8. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    I'm not sure what you're doing wrong there, that should work, since I just pasted your scripts in and they did, after restarting acpid of course. But, you don't need to make a script for that, just make an association in the System->Preferences->Keyboard Shortcuts->Custom Shortcuts for rhythmbox.

    In terms of your calculator not working without hitting another key, I don't understand what you mean, so here are my scripts, which I substituted 0x8a for, since I had nothing bound there:

    /etc/acpi/events/asus-calc
    Code:
    event=hotkey ATKD 0000008a
    action=/etc/acpi/asus-calc.sh
    /etc/acpi/asus-calc.sh
    Code:
    #!/bin/sh
    
    test -f /usr/share/acpi-support/key-constants || exit 0 
    . /usr/share/acpi-support/key-constants
    acpi_fakekey $KEY_CALC
    
     
  9. LostHero

    LostHero Newbie

    Reputations:
    0
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    5
    The problem with using System->Preferences->Keyboard Shortcuts->Custom Shortcuts to make a rhythmbox shortcut is that I also want it to play/pause when the application is open. I'm limited to one shortcut per key when using that program (unless I'm unaware of something).

    The only difference between my calculator scripts and yours is that you used
    Code:
    event=hotkey ATKD 0000008a
    while I used
    Code:
    event=hotkey (ATKD|HOTK) 000000b5
    so I changed mine to
    Code:
    event=hotkey ATKD 000000b5
    and it still doesn't work.

    The problem is that after pressing Fn-Enter, nothing happens until I press something else on the keyboard (such as the spacebar). It doesn't seem to matter how long an interval is between the Calc button and the keyboard button but the calculator doesn't appear until I hit the keyboard button.

    The shell file was compiled using "chmod 755 asus-calc.sh" and I have been remembering to restart acpid so I've got no idea what the problem is.

    BTW, thanks for your help thus far.
     
  10. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
  11. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    OK, I understand what you want to do with the play/pause button... did you get that working?

    About the calculator, try running sudo dbus-monitor --system (without piping it to grep), does the event come through when you've pressed Fn+Enter or after the subsequent keypress? I'm assuming that the key gets picked up by acpi_listen immediately. You may want to run both at the same time in a separate window actually.

    Maybe try changing it to 0x8a (Fn+C / 'Splendid') to see if you have the same problem as 0xb5.

    Also, what distro/version are you on, I'm on Debian Sid AMD64.

    I could give you instructions for modifying asus-laptop.c but I need to know if you're on a custom or stock kernel.
     
  12. LostHero

    LostHero Newbie

    Reputations:
    0
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    5
    The play/pause button is still not working to start rhythmbox.

    I tried running "sudo dbus-monitor --system" but I'm not sure how to read its output. On a side note, while running that command, nothing was shown after pressing Fn-Enter until I hit a second button. If I used Fn-Enter as the second button, the first Fn-Enter activated but the second waited for a key press. Unfortunately, when I press Fn-Enter in the normal graphical interface, the calculator(s) won't show up until I hit a normal button (so I can't just get into the habit of hitting the hotkey twice).

    I experienced the same problem after changing the hotkey to 0x8a (Fn+C / 'Splendid' Button). While running acpi_listen, most of my hotkeys start with "^@" but any hotkeys that I assign using my calculator script end with at least one "^@" (with nothing at the beginning). This seems like a side effect of something so I hope this helps diagnose my problem.

    I am running "Ubuntu 10.04.1 LTS - Lucid Lynx" with a stock kernel.

    Edit: I did a search of my File System but the only files labeled as asus-laptop were 3 files by the name of "asus-laptop.ko" (I even searched the hidden files).
     
  13. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    That's weird, dbus doesn't show the event until you hit another key, and you're getting nulls (^@) before/after your scancodes?

    Maybe this is a bug somewhere, I have no problems doing exactly what you want to do on Sid. Does the same thing happen for all other hotkeys?

    Modifying the kernel module is not for beginners. At your own risk, here is how to accomplish that. It's not going to do anything for your play/pause idea, but it will fix your calculator issue, if it can be fixed at all.

    First back up the existing module (don't run this twice, see below to restore):
    Code:
    sudo cp /lib/modules/`uname -r`/kernel/drivers/platform/x86/asus-laptop.ko /lib/modules/`uname -r`/kernel/drivers/platform/x86/asus-laptop.ko.bak
    Install stuff you need:
    Code:
    sudo apt-get install linux-source-2.6 linux-headers-`uname -r` build-essential libncurses5 libncurses5-dev kernel-package fakeroot
    Now extract the kernel sources to a folder named src in your home directory:
    Code:
    mkdir ~/src
    cd ~/src
    tar jxvf /usr/src/linux-source-2.6.32.tar.bz2
    cd linux-source-2.6.32
    cp /boot/config-`uname -r` .config
    make oldconfig
    
    Change 0x55 to 0xb5 on the line (around 314) that reads {KE_KEY, 0x55, KEY_CALC}, and save the file:
    Code:
    gedit +314 drivers/platform/x86/asus-laptop.c &
    Code:
    	{KE_KEY, 0xb5, KEY_CALC},
    Build..
    Code:
    make -C /usr/src/linux-headers-`uname -r` SUBDIRS=`pwd` drivers/platform/x86/asus-laptop.ko
    Test..
    Code:
    sudo modprobe -r asus_laptop
    sudo insmod drivers/platform/x86/asus-laptop.ko
    If it doesn't work:
    Code:
    sudo modprobe -r asus_laptop
    sudo modprobe asus_laptop
    If it works, you can copy it to /lib/modules to make it permanent:
    Code:
    sudo cp drivers/platform/x86/asus-laptop.ko /lib/modules/`uname -r`/kernel/drivers/platform/x86/asus-laptop.ko
    If you did the above permanent change and broke something, restore the original:
    Code:
    sudo cp /lib/modules/`uname -r`/kernel/drivers/platform/x86/asus-laptop.ko.bak /lib/modules/`uname -r`/kernel/drivers/platform/x86/asus-laptop.ko