Lisp HUG Maillist Archive

How to test if option or control key is pressed?

Hi, this is probably very easy to do in LW - but I did not find a solution from Google.

- How to test if option or  control key is pressed in the LW Mac?

It should be easy-callable, for  example:

… happening anywhere in the code

(if (option-key-down)
  …)

…

Does anybody have any ideas how to make it?

Pekka


Re: How to test if option or control key is pressed?

Re: How to test if option or control key is pressed? Hi Pekka,

Please, note that this solution is not “standard” and that this is not possible without an interface opened

Best regards

Denis

(in-package :capi)

(defconstant _capsLock_key (byte 1 0))
(defconstant _shift_key (byte 1 1))
(defconstant _control_key (byte 1 2))
(defconstant _option_key (byte 1 3))
(defconstant _command_key (byte 1 4))

(defun get-modifiers (pane)
  (let* ((interface (top-level-interface pane))
           (wptr (slot-value (representation interface) 'capi-cocoa-library::window))) ;===> this sentence use non external symbols
   (if wptr
      (let* ((event (objc:invoke wptr "currentEvent"))
             (flags (objc:invoke event "modifierFlags")))
        (ldb (byte 5 16) flags))
      0)))

(defun command-key-p (pane-or-modifiers)
  (unless (numberp pane-or-modifiers) (setf pane-or-modifiers (get-modifiers pane-or-modifiers)))
  (ldb-test _command_key pane-or-modifiers))

;etc. (same thing for other modifiers)


;=============TEST
(defparameter mypane (contain (make-instance 'output-pane)))
(command-key-p mypane)
OR
(let ((modifiers (get-modifiers  mypane)))
    (command-key-p modifiers)) ;Which is more efficient if you need several calls in a single function
;=============

Le 7/10/11 9:11, « [NOM] » <[ADRESSE]> a écrit :

>
> Hi, this is probably very easy to do in LW - but I did not find a solution
> from Google.
>
> - How to test if option or  control key is pressed in the LW Mac?
>
> It should be easy-callable, for  example:
>
> … happening anywhere in the code
>
> (if (option-key-down)
>   …)
>
> …
>
> Does anybody have any ideas how to make it?
>
> Pekka
>

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgium

Tel : 32 (0)2 219 31 09
Email :  denis.pousseur@gmail.com
Website : http://www.denispousseur.com
-------------------------------------------------------

Re: How to test if option or control key is pressed?

Hi Denis,

You can also call currentEvent on the singleton instance NSApplication. All you need is an application initialized with NSApplicationMain().


--
Camille


On 8 oct. 2011, at 19:40, Denis Pousseur <denis.pousseur@gmail.com> wrote:

Hi Pekka,

Please, note that this solution is not “standard” and that this is not possible without an interface opened

Best regards

Denis

(in-package :capi)

(defconstant _capsLock_key (byte 1 0))
(defconstant _shift_key (byte 1 1))
(defconstant _control_key (byte 1 2))
(defconstant _option_key (byte 1 3))
(defconstant _command_key (byte 1 4))

(defun get-modifiers (pane)
  (let* ((interface (top-level-interface pane))
           (wptr (slot-value (representation interface) 'capi-cocoa-library::window))) ;===> this sentence use non external symbols
   (if wptr
      (let* ((event (objc:invoke wptr "currentEvent"))
             (flags (objc:invoke event "modifierFlags")))
        (ldb (byte 5 16) flags))
      0)))

(defun command-key-p (pane-or-modifiers)
  (unless (numberp pane-or-modifiers) (setf pane-or-modifiers (get-modifiers pane-or-modifiers)))
  (ldb-test _command_key pane-or-modifiers))

;etc. (same thing for other modifiers)


;=============TEST
(defparameter mypane (contain (make-instance 'output-pane)))
(command-key-p mypane)
OR
(let ((modifiers (get-modifiers  mypane)))
    (command-key-p modifiers)) ;Which is more efficient if you need several calls in a single function
;=============

Le 7/10/11 9:11, « [NOM] » <[ADRESSE]> a écrit :

>
> Hi, this is probably very easy to do in LW - but I did not find a solution
> from Google.
>
> - How to test if option or  control key is pressed in the LW Mac?
>
> It should be easy-callable, for  example:
>
> … happening anywhere in the code
>
> (if (option-key-down)
>   …)
>
> …
>
> Does anybody have any ideas how to make it?
>
> Pekka
>

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgium

Tel : 32 (0)2 219 31 09
Email :  denis.pousseur@gmail.com
Website : http://www.denispousseur.com
-------------------------------------------------------

Re: How to test if option or control key is pressed?

Re: How to test if option or control key is pressed? You’re right, it’s possible to avoid interned symbols. The current application can also be found with (objc:invoke “NSApplication” “sharedApplication”) which points to the LW application in a development environment and to your application in a delivery environment.

Best regards

Denis

Le 8/10/11 19:50, « [NOM] » <[ADRESSE]> a écrit :

Hi Denis,

You can also call currentEvent on the singleton instance NSApplication. All you need is an application initialized with NSApplicationMain().


--
Camille


On 8 oct. 2011, at 19:40, Denis Pousseur <denis.pousseur@gmail.com> wrote:

Hi Pekka,

Please, note that this solution is not “standard” and that this is not possible without an interface opened

Best regards

Denis

(in-package :capi)

(defconstant _capsLock_key (byte 1 0))
(defconstant _shift_key (byte 1 1))
(defconstant _control_key (byte 1 2))
(defconstant _option_key (byte 1 3))
(defconstant _command_key (byte 1 4))

(defun get-modifiers (pane)
  (let* ((interface (top-level-interface pane))
           (wptr (slot-value (representation interface) 'capi-cocoa-library::window))) ;===> this sentence use non external symbols
   (if wptr
      (let* ((event (objc:invoke wptr "currentEvent"))
             (flags (objc:invoke event "modifierFlags")))
        (ldb (byte 5 16) flags))
      0)))

(defun command-key-p (pane-or-modifiers)
  (unless (numberp pane-or-modifiers) (setf pane-or-modifiers (get-modifiers pane-or-modifiers)))
  (ldb-test _command_key pane-or-modifiers))

;etc. (same thing for other modifiers)


;=============TEST
(defparameter mypane (contain (make-instance 'output-pane)))
(command-key-p mypane)
OR
(let ((modifiers (get-modifiers  mypane)))
    (command-key-p modifiers)) ;Which is more efficient if you need several calls in a single function
;=============

Le 7/10/11 9:11, « [NOM] » <[ADRESSE]> a écrit :

>
> Hi, this is probably very easy to do in LW - but I did not find a solution
> from Google.
>
> - How to test if option or  control key is pressed in the LW Mac?
>
> It should be easy-callable, for  example:
>
> … happening anywhere in the code
>
> (if (option-key-down)
>   …)
>
> …
>
> Does anybody have any ideas how to make it?
>
> Pekka
>

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgium

Tel : 32 (0)2 219 31 09
Email :  denis.pousseur@gmail.com <mailto:denis.pousseur@gmail.com>
Website : http://www.denispousseur.com <http://www.denispousseur.com>
-------------------------------------------------------



-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgium

Tel : 32 (0)2 219 31 09
Email :  denis.pousseur@gmail.com
Website : http://www.denispousseur.com
-------------------------------------------------------
Updated at: 2020-12-10 08:37 UTC