PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 8ms

/extra/key-logger/key-logger.factor

http://github.com/abeaumont/factor
Unknown | 35 lines | 28 code | 7 blank | 0 comment | 0 complexity | 1a91a91994909ea4545be033cd81b78f MD5 | raw file
 1! Copyright (C) 2010 Doug Coleman.
 2! See http://factorcode.org/license.txt for BSD license.
 3USING: accessors timers bit-arrays calendar game.input io
 4io.binary io.encodings.binary io.files kernel literals math
 5namespaces system threads ;
 6IN: key-logger
 7
 8CONSTANT: frequency $[ 1/30 seconds ]
 9
10CONSTANT: path "resource:key-log.txt"
11
12: update-key-caps-state ( -- )
13    read-keyboard keys>>
14    path binary [
15        [ gmt unix-1970 time- duration>nanoseconds >integer ]
16        [ bit-array>integer ] bi*
17        [ 8 >be write ] bi@ flush
18    ] with-file-appender ;
19
20SYMBOL: key-logger
21
22: start-key-logger ( -- )
23    key-logger get-global [
24        [
25            open-game-input
26            [ update-key-caps-state ] frequency every key-logger set-global
27        ] in-thread
28    ] unless ;
29
30: stop-key-logger ( -- )
31    key-logger get-global [ stop-timer ] when*
32    f key-logger set-global
33    close-game-input ;
34
35MAIN: start-key-logger