Tải bản đầy đủ - 0 (trang)
Hack 48. Enable Your Multimedia Keyboard

Hack 48. Enable Your Multimedia Keyboard

Tải bản đầy đủ - 0trang

Clickontheshortcutentryforanactionandthenpressthekey

combinationyouwanttoassociatewithit.Forexample,ifyou

wantF7tolaunchyourwebbrowser,clicktheshortcutentry

nextto"Launchwebbrowser"andthenpressF7.Changesare

appliedimmediately,sothereisnoneedtosavethenew

settings.

Thebuilt-inGNOMEkeyboard-shortcutsettingsincludeonly

predefinedactions,soifyouwanttolaunchacustomscriptor

anarbitraryprogram,you'llneedsomethingmoreflexible,such

asHotkeys.



Hotkeys

Hotkeysisaprogramthatinterceptskeycodesfrommultimedia

keysandmapsthemtospecificevents.Theeventsaretotally

user-definable,soyoucanconfigurekeystorunprogramsor

evencustomscripts.Forexample,inadditiontobasicactions

suchascontrollingvolume,openingemail,orlaunchinga



browser,youcansetkeystodothingssuchasinitiateanSSH

connectiontoaremotemachine,changeyourdesktop

background,launchOpenOffice.org,startabackup,orpretty

muchanythingelseyoucanthinkof.

Hotkeysisintheuniversegroupofextrasoftwarethat'snot

officiallysupportedbyUbuntu,soifyourcomputerisnotsetto

usesoftwarefromuniverse,youmayneedto"ModifytheListof

PackageRepositories"[Hack#60]beforeyoucaninstallit:

$sudoapt-getinstallhotkeys





UnderstandHotkeysconfigurationparsing

BecauseHotkeysusesatwo-stageconfigurationsystem,itmay

notbeimmediatelyobviouswhatyouneedtochangeto

customizecommands,andsometimesthechangesyoumake

don'tseemtobeapplied.However,itallmakesperfectsense

onceyouunderstandhowHotkeysparsesitsconfigurationfiles.

Thefirststageisthekeyboarddefinitionfile,whichdoestwo

kindsofmapping:indirectconversionofkeycodestopredefined

events,anddirectconversionofkeycodestouser-defined

commands.ThesecondstageistheHotkeysconfigurationfile,

whichdoesasecondmappingforpredefinedevents,associating

themwithexplicitcommands.

ThisapproachallowsHotkeystomapthekeycodegeneratedby

theFavoritesbuttononyourkeyboardwithapredefined

Favoriteseventusingthekeyboarddefinition,andthenmapthe

Favoriteseventtoaspecificcommandsuchasgnome-moz-remote-remote=openBookmarksintheHotkeysconfiguration.Thatway,the

majorityofstandardactionscanbedefinedintheHotkeys



configuration,andmakingthemworkwithadifferentkeyboard

isjustamatterofswitchingthekeyboarddefinitionfile.

However,youcanalsodefinecustomeventsrightinthe

keyboarddefinition.Thisapproachmapsakeycodestraighttoa

commanddirectlywithoutreferringtotheHotkeysconfiguration

fileatall.Thisishowyouwillprobablydefinemoreunusual

actions,suchaslaunchingaterminalandautomaticallyopening

anSSHsessiontoapredefinedhost.



Setkeyboardtype

ThefirststeptoconfiguringHotkeysistodefineyourkeyboard

typesothecorrectkeycodescanberecognized.Hotkeyscomes

withsampleconfigurationsforavarietyofstandardkeyboard

types,soifyou'relucky,youmaybeabletojustselectyour

keyboardfromthesamplesandeverythingwilljustwork.To

seealistofsupportedkeyboardtypes,run:

$hotkeys-l





Thenyoucanspecifyoneofthosekeyboardtypeswhenyou

launchHotkeysusingthe-tflag.

Butwhatifyourkeyboardisn'tinthelistofsupportedmodels?

Noproblem.Youcandefineacustomkeyboardtypebycopying

the/usr/share/doc/hotkeys/sample.xmlsamplefileintoa

.hotkeysdirectoryinsideyourhomedirectory,andyoucanthen

customizetheentriesinittomatchthekeycodesreturnedby

yourkeyboard:



$mkdir~/.hotkeys

$cp/usr/share/doc/hotkeys/sample.xml~/.hotkeys/mykeyboard.de







BesuretocheckovertheXMLinthisfile.Atthetimeofthiswriting,

thetagattheendofthefilewasimproperlyclosed(it

shouldbe
).



Ifyouthenrunhotkeys-lagain,you'llseethereisnowa

keyboardtypeofmykeyboardatthetopofthelistinadditionto

allthedefaultkeyboards.Youcanlaterrefertoyourcustom

keyboardlayoutbynamewhenlaunchingHotkeys.

Thesamplefileiscommented,butitmaymakemoresenseif

youhavealookatoneofthekeyboarddefinitionfilesprovided

in/usr/share/hotkeys/toseehowtheyarestructured.Youmay

evenprefertostartbycopyingoneofthesupplieddefinitions

insteadifyoufindonethatisclosetowhatyouwant.

Tosetupthefile,youwillneedtoknowtheexactkeycodesfor

thevariousmultimediakeysyouwishtouse.Youcandetect

keycodesusingautilitycalledxev("Xevents"),whichdoes

nothingbutwatchinputdevicesincludingthemouseand

keyboardanddisplaythecodesofanyeventssenttoX.By

runningxevandthenpressingeachofyourmultimediakeysin

turn,youcanseeexactlywhatisbeingreturnedandthenadd

thosecodestoyour.hotkeys/mykeyboard.deffile.First,install

xev:

$sudoapt-getinstallxev





Thenlaunchxevfromaterminaltoopenasmalltestwindow.

Setthemouse'sfocusonthetestwindowandthenpressoneof

themultimediakeys.Intheterminalthatyouusedtolaunch

xev,youwillseeseverallinesofeventinformationreportedfor

eachkeypress.Whatyouneedtolookforisanentrythatsays

keycodewithanumberafterit.Thatnumberisthekeycodethat

isassociatedwiththatparticularkeybyX.Writedownalistof

themultimediakeysandtheirmatchingkeycodes.

Onceyouhavefinishedwithxev,youcancloseitusingCtrl-Cin

theoriginalterminalorbyclickingthecloseboxinthewindow

manager.

Next,youneedtoopenyour.hotkeys/mykeyboard.defconfig

fileinatexteditorandmatcheventstokeycodesaccordingto

thelistyoujustmade.Forexample,tomatchkeycode178to

theFavoritesevent,youwouldmakeanentrylike:





Thesamplefilecontainsanumberofpredefinedeventsthat

youcanuncommentandconfiguretosuityourkeycodes.



Customizepredefinedactions

NowthatHotkeyshasamappingbetweenkeycodesand

predefinedactions,youcancustomizethecommandassociated

witheachaction.Theglobalconfigfileislocatedin

/etc/hotkeys.conf,butifyouwanttocustomizetheactionlist,

youcanmakealocalcopythatwillautomaticallyoverridethe

globalconfig:

$cp/etc/hotkeys.conf~/.hotkeys/hotkeys.conf





Followingtheexampleabove,youcouldtellHotkeystoopen

yourFavoriteslistinMozillawithanentrylike:

Favorites=gnome-moz-remote--remote=openBookmarks



Createcustomactions

Thepreviousstepallowsyoutocustomizethepredefined

actions,butthat'snotmuchuseifyouwantanactionlike

"LaunchxtermwithreversedvideoandopenanSSHsessionto

www.example.com"!Noproblem:youcanusethekeyboard

definitionfiletoassociatekeycodeswithanyarbitrarycommand

youlike.Forexample,ifyouwantedtousetheF2keyfora

purposesuchasopeninganSSHsessiontoaremotemachine,

youcouldusexevtofindthekeycodeforF2andedit

~/.hotkeys/mykeyboard.defandputin:






Inthiscase,68isthekeycodeforF2,andSSHwww.example.comis

theeventlabelthatwillbedisplayedonscreenbyHotkeyswhen

itexecutesthecommand.



TestHotkeys

Nearlythere!Bynow,youhaveakeyboarddefinitionfilethat

mapskeycodestoactions,plusaHotkeysconfigurationfilethat

mapsactionstocommands.Nowit'stimetolaunchHotkeys



andtryitout.

Specifythekeyboardtypeandlaunchhotkeysitself:

$hotkeys-tmykeyboard-b





The-bflagtellsHotkeysnottolaunchitselfintothe

background;thatmakesiteasiertomakequickchangesif

thingsdon'tgoquiteasplanned,becauseyoucanjustCtrl-Cto

killtheprogramandlaunchitagain.Later,whenyou'rehappy

withtheconfiguration,youcanleaveoffthe-b,andHotkeyswill

automaticallybackgrounditselfonstartup.

Alternatively,ifHotkeysisbackgroundedandyouwanttomake

changes,youcansimplyuse:

$killallhotkeys





andthenlaunchitagain.

Assoonasyoulaunchit,Hotkeyswillstartwatchingforkeypressevents,sotrypressingoneofthekeysyoumappedand

seewhathappens.

Tosaveyourselfthehassleofpassingthekeyboard-type

argumenttoHotkeyseverytime,youcanputanentryin

.hotkeys/hotkeys.conflikethis:

Kbd=mykeyboard



whichwillthenbeappliedautomatically.



Onscreendisplaysettings

Hotkeysdisplayseachactiononscreenwhileit'sexecutingitto

giveyoufeedbackthatsomethingishappening.Bydefault,the

OSDislarge,brightgreen,andhangsaroundonyourdisplay

foracoupleofseconds,soyoumaywanttochangethe

settingstomakeitlessobtrusive.

Lookatthebottomofyourhotkeys.conffileforsettingsstarting

withosd_.Thesampleconfigurationiswellcommented,somake

changesasyouseefit,andthenkillandrelaunchHotkeysfor

yourchangestotakeeffect.



StartHotkeysAutomatically

BecauseHotkeysneedstoberunningtodoitsjob,youwill

needtolaunchiteverytimeyoulogintoX.Thatcanbeapain,

sotohaveitstartautomatically,justaddittotheStartup

ProgramsinSystem Preferences Sessions.ClickAddand

typeinthecommandyouusedtolaunchHotkeysfromthe

commandline,thensaveit(seeFigure5-2).



Figure5-2.AddHotkeystoStartupProgramsin

yoursession



ThenexttimeyoulogintoGNOME,Hotkeyswillbestartedfor

youautomaticallyandyourmultimediakeyswillbefunctional

rightaway.



Hack49.ConfigureaTouchpad



Configurethespecialfunctionsofyourlaptoptouchpad

andstarttappinglikecrazy.

Mostlaptopstodayincludeatouchpadasamethodof

controllingthemousepointer.Thesetouchpadshavevarious

configurationoptionsthatmostpeoplearen'tevenawareof.

Here'showtogetalltheseadvancedfeaturesworkingunder

Linux.

Ubuntuincludesthesynapticsmousedriverbydefault,andif

yourlaptop'stouchpadisdetectedduringinstallation,itwillbe

automaticallyinstalledandconfigured.Thestocktouchpad

configurationwillincludesomeadvancedfeatureslikedoublefingertapsupportformiddle-clicksandusingtherightsideof

thetouchpadtodoverticalscrolling.Toreallytweakyour

touchpadconfiguration,though,youmustmakeasmalleditto

yourX11configuration,restarttheGUI,andinstalla

configurationprogram.



PreparingYourX11Configuration

Inordertousetheconfigurationprogramforyourtouchpad,

firstyoumustedittheX11configurationtoaddadirectiveto

enablesharedmemoryintheXserver.Ifyou'refairlynewto

Linux,wesuggestyouusethenanoeditor;otherwise,usethe

editorofyourchoice.



ThepermissionsontheX11configurationarerestricted,soyouneedto

makethischangeusingsudo.



Backuptheconfigurationfilefirst:



bill@lexington:~$sudocp/etc/X11/xorg.conf/etc/X11/xorg.conf





Theneditthefile:

bill@lexington:~$sudonano/etc/X11/xorg.conf





Onceyougetthefileopen,youshouldseeasectionpertaining

tothetouchpad.Itmaylooklikethis:

Section"InputDevice"

Identifier"SynapticsTouchpad"

Driver"synaptics"

Option"SendCoreEvents""true"

Option"Device""/dev/psaux"

Option"Protocol""auto-dev"

Option"HorizScrollDelta""0"

EndSection



You'llneedtoaddalineinthatsectionofthefile(beforethe

EndSectionline)withtheSHMConfigoptionsettoon(thiswillallow

youtousetheGUIclienttomakechangeswithoutrestarting

theXorgserver).Hereisasamplesnippetafterediting:

Section"InputDevice"



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 48. Enable Your Multimedia Keyboard

Tải bản đầy đủ ngay(0 tr)

×