cl-rw

Layered streams for Common Lisp
git clone https://logand.com/git/cl-rw.git/
Log | Files | Refs

input.lisp (1754B)


      1 ;;; Copyright (C) 2015 Tomas Hlavaty <tom@logand.com>
      2 ;;;
      3 ;;; Permission is hereby granted, free of charge, to any person
      4 ;;; obtaining a copy of this software and associated documentation
      5 ;;; files (the "Software"), to deal in the Software without
      6 ;;; restriction, including without limitation the rights to use, copy,
      7 ;;; modify, merge, publish, distribute, sublicense, and/or sell copies
      8 ;;; of the Software, and to permit persons to whom the Software is
      9 ;;; furnished to do so, subject to the following conditions:
     10 ;;;
     11 ;;; The above copyright notice and this permission notice shall be
     12 ;;; included in all copies or substantial portions of the Software.
     13 ;;;
     14 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     15 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     16 ;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     17 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
     18 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     19 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20 ;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21 ;;; DEALINGS IN THE SOFTWARE.
     22 
     23 (defpackage :rw.linux.input
     24   (:use :cl))
     25 
     26 (in-package :rw.linux.input)
     27 
     28 (defun mouse-event-reader (octet-reader)
     29   (lambda ()
     30     (let ((i1 (rw:next octet-reader)))
     31       (when i1
     32         (let ((i2 (rw:next octet-reader))
     33               (i3 (rw:next octet-reader)))
     34           ;; left i1 & 1
     35           ;; middle i1 & 4
     36           ;; right i1 & 2
     37           ;; x i2 y i3
     38           (list i1 i2 i3))))))
     39 
     40 #+nil
     41 (with-open-file (s "/dev/input/mice"
     42                    :element-type '(unsigned-byte 8))
     43   (let ((r (mouse-event-reader (rw:byte-reader s))))
     44     (dotimes (i 100)
     45       (print (rw:next r)))))