Linux 筆記本基于“敲打”的命令
xscreensaver 所使用的命令配置
以下設(shè)置假設(shè)您已經(jīng)登錄到了窗口管理器中并且已經(jīng)使用您的 userid 啟動(dòng)了xscreensaver 程序例如如果您正在運(yùn)行 Fedora Core 并且使用 gdm 登錄到 KDE 中那么 xscreensaver 就會(huì)自動(dòng)啟動(dòng)因此要激活它則需要將雙擊命令從
/bin/echo double tap
修改為
xscreensavercommand activate
現(xiàn)在每次識(shí)別出有 雙擊 事件發(fā)生時(shí)xscreensaver 程序都會(huì)使用所指定的內(nèi)容來激活一旦 screensaver 被激活就可以通過輸入密碼(如果是這樣配置的)對(duì)屏幕進(jìn)行解鎖不過我們真正希望的是自己的朋友也可以使用密碼解鎖代碼來解除屏保因此我們需要在 ~/knockFile 文件中將下面的命令
/bin/echo shave the haircut
替換為
killall xscreensaver ; nohup xscreensaver nosplash >/dev/null >/dev/null
這個(gè)命令會(huì)停止當(dāng)前運(yùn)行的所有 xscreensaver 程序然后在后臺(tái)再重新啟動(dòng) xscreensaver現(xiàn)在我們可以通過敲打屏幕邊來重復(fù)加鎖和解鎖計(jì)算機(jī)屏保的過程這比藍(lán)牙提供的近似度加鎖更加安全或更方便嗎?答案可能是否定的它更酷嗎?當(dāng)然!
更多例子
HDAPS 傳感器和 knockAgepl 程序提供了另外一種用戶輸入設(shè)備我們可以使用它們以獨(dú)特的方式進(jìn)行輸入例如
如果計(jì)劃在一個(gè)基礎(chǔ)上測試新的 X 配置文件可以將雙擊條目更改為重新啟動(dòng)配置好的 X 服務(wù)器這樣就不需要敲任何其他鍵來強(qiáng)制重啟了
在命令區(qū)中可以放上我們喜歡使用的任何 shell 腳本這樣就可以使用雙擊來查看 email
以最新的組合節(jié)拍進(jìn)行敲打讓 ThinkLight 顯示 WWII 代在 Kinakuta 的黃金存儲(chǔ)設(shè)備的 Morse 密碼位置
敲入 Morse 編碼防止鍵盤輸入被記錄
請參閱 參考資料 部分給出的有關(guān)將 ThinkPad 的傾斜度用于游戲顯示工具的例子或者直接跳過這部分內(nèi)容將 Threshold 變量設(shè)置為 這樣您使勁踢一腳 ThinkPad它就會(huì)自動(dòng)重啟了
knockAgepl 代碼
歷史和策略
Jeff Molofee 所編寫的 hdapsglc 是 knockAgepl 代碼的基礎(chǔ)Hdapsglc 是一個(gè)非常好的展示程序可以展示如何使用傾斜傳感器來實(shí)時(shí)地顯示有關(guān) ThinkPad 的方向的信息二者之間的區(qū)別是本例將時(shí)間上隔離的事件組織在一起創(chuàng)建了敲打事件同時(shí)提供了相關(guān)的代碼來創(chuàng)建并監(jiān)聽敲打事件序列
參數(shù)配置
下面讓我們來使用對(duì)時(shí)間和傳感器敏感的一些參數(shù)來啟動(dòng) knockAgepl
清單 主程序參數(shù)
require sys/syscallph; # for subsecond timing my $option = $ARGV[] || ; # simple option handling # filename for hdaps sensor reads my $hdapsFN = /sys/devices/platform/hdaps/position; my $UPDATE_THRESHOLD = ; # threshold of force that indicates a knock my $INTERVAL_THRESHOLD = ; # microseconds of time required between knock # events my $SLEEP_INTERVAL = ; # time to pause between hdaps reads my $MAX_TIMEOUT_LENGTH = ; # maximum length in seconds of knock pattern # length my $MAX_KNOCK_DEV = ; # maximum acceptable deviation between recorded # pattern values and knocking values my $LISTEN_TIMEOUT = ; # timeout value in seconds between knock # events when in listening mode
這些變量及其注釋都非常簡單它們的用法和配置選項(xiàng)在本文后面部分會(huì)進(jìn)行解釋下面是其余的一些全局變量及其描述
清單 敲打模式參數(shù)
my @baseKnocks = (); # contains knock intervals currently entered my %knockHash = (); # contains knock patterns associated commands my $prevInterval = ; # previous interval of time my $knockCount = ; # current number of knocks detected my $restX = ; # `resting positiong of X axis accelerometer my $restY = ; # `resting positiong of Y axis accelerometer my $currX = ; # current position of X axis accelerometer my $currY = ; # current position of Y axis accelerometer my $lastX = ; # most recent position of X axis accelerometer my $lastY = ; # most recent position of Y axis accelerometer my $startTime = ; # to manage timeout intervals my $currTime = ; # to manage timeout intervals my $timeOut = ; # perpetual loop variable my $knockAge = ; # count of knocks to cycle time interval
子程序
在我們的子程序清單中首先是一個(gè)簡單的邏輯塊用來檢查是否有加速器可讀
清單 檢查加速器的子程序
sub checkAccelerometer() { my $ret; $ret = readPosition (); if( $ret ){ print no accelerometer data available tis bork edn; exit(); } }#checkAccelerometer
Jeff Molofee 編寫的 hdapsglc 代碼為 knockAgepl 中的所有代碼提供了一個(gè)很好的起點(diǎn)在下面的 readPosition 子程序中我們可以看到他的注釋這個(gè)子程序?qū)⒋蜷_一個(gè)文件從中讀取當(dāng)前的加速器數(shù)據(jù)然后關(guān)閉文件并返回不包含 (逗號(hào)) 字符的數(shù)據(jù)
清單 readPosition subroutine
## comments from Jeff Molofee in hdapsglc #* read_position read the (xy) position pair from hdaps #* #* We open and close the file on every invocation which is lame but due to #* several features of sysfs files: #* #* (a) Sysfs files are seekable #* (b) Seeking to zero and then rereading does not seem to work ## sub readPosition() { my ($posX $posY) = ; my $fd = open(FH $hdapsFN); while( ){ s/(//g; s/)//g; ($posX $posY) = split ; }# while read close(FH); return( $posX $posY ); }#readPosition
getEpochSeconds 和 getEpochMicroSeconds 提供了有關(guān)敲打模式狀態(tài)的詳細(xì)而精確的信息
清單 時(shí)間分隔器
sub getEpochMicroSeconds { my $TIMEVAL_T = LL; # LL for microseconds my $timeVal = pack($TIMEVAL_T ()); syscall(SYS_gettimeofday $timeVal ) != or die micro seconds: $!; my @vals = unpack( $TIMEVAL_T $timeVal ); $timeVal = $vals[] $vals[]; $timeVal = substr( $timeVal ); my $padLen = length($timeVal); $timeVal = $timeVal x $padLen; return($timeVal); }#getEpochMicroSeconds sub getEpochSeconds { my $TIMEVAL_T = LL; # LL for microseconds my $start = pack($TIMEVAL_T ()); syscall(SYS_gettimeofday$start ) != or die seconds: $!; return( (unpack($TIMEVAL_T $start))[] ); }#getEpochSeconds
評(píng)論