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

http://github.com/abeaumont/factor · Factor · 35 lines · 26 code · 7 blank · 2 comment · 2 complexity · 1a91a91994909ea4545be033cd81b78f MD5 · raw file

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