# Openmoko Key Mapping Functions # Version: 1.0 #Copyright (c) 2008 Bryan DeLuca #All rights reserved. # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions #are met: #1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. #2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. #3. Neither the name of the author nor the names of other contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # #THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND #ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE #FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL #DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS #OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) #HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT #LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY #OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF #SUCH DAMAGE. # # ## Example of using this software. In your startup script referenced by your #.desktop file you only need to include 3 lines to implement this script. #Here is how you could map the AUX key to F5: # # . omkey_functions # # om_key_mod 177 F5 # # run_my_sweet_app # # om_key_restore # #And that's it! Several global variables will be used (all beginning with omkey_*) #to save keymap info. So, be careful not to step on those. # om_key_mod () { # Declare some local variables local AUX_KEYCODE i MAP_KEY retval # 1st argument is the hardware keycode for the AUX button, should be 177 AUX_KEYCODE="${1}" # 2nd argument is the new key to map AUX to MAP_KEY="${2}" # Save current AUX Key mapping omkey_xmod_save_key="$(xmodmap -pke | grep 'keycode ${AUX_KEYCODE}')" # Detect if we are running Enlightenment if [ ${E_IPC_SOCKET} ]; then # Find the enlightenment key bindings for AUX for i in `enlightenment_remote -binding-key-list|grep Keycode-${AUX_KEYCODE}`; do case $i in CONTEXT=*) omkey_er_context=${i#CONTEXT=} ;; KEY=*) omkey_er_key=${i#KEY=};; MODIFIERS=*) omkey_er_modifiers=${i#MODIFIERS=};; ANY_MOD=*) omkey_er_any_mod=${i#ANY_MOD=};; ACTION=*) omkey_er_action=${i#ACTION=};; PARAMS=*) omkey_er_params=${i#PARAMS=};; *) esac done fi; # Change Key Binds if [ ${omkey_er_key} ]; then # Remove the Enlightenment binding for the AUX button eval enlightenment_remote -binding-key-del ${omkey_er_context} ${omkey_er_key} ${omkey_er_modifiers} ${omkey_er_any_mod} ${omkey_er_action} ${omkey_er_params} retval=$? fi; # Map AUX Key as requested xmodmap -e "keycode ${AUX_KEYCODE} = ${MAP_KEY}" i=$? if [ ${i} -ne 0 ]; then retval=${i} fi; return ${retval}; } om_key_restore () { # Restore key binds based on global variables # Declare local variables local i retval # Restore the AUX Key mapping xmodmap -e "${omkey_xmod_save_key}" retval=$? if [ ${omkey_er_key} ]; then # Restore the Enlightenment binding for AUX eval enlightenment_remote -binding-key-add ${omkey_er_context} ${omkey_er_key} ${omkey_er_modifiers} ${omkey_er_any_mod} ${omkey_er_action} ${omkey_er_params} i=$? if [ ${i} -ne 0 ]; then retval=${i} fi; fi; return ${retval}; }