Author Topic: [XDrX-Hook]WINDOWS hook (HOOK) function (1) - MASK the ESC key  (Read 1087 times)

0 Members and 1 Guest are viewing this topic.

xdcad

  • Swamp Rat
  • Posts: 527
[XDrX-Hook]WINDOWS hook (HOOK) function (1) - MASK the ESC key
« on: November 18, 2023, 07:49:56 AM »

For information on using the WINDOWS message loop in LISP, see:

http://www.theswamp.org/index.php?topic=58729.0

Sometimes if you want your program not to be terminated by ESC, you can temporarily block the ESC key. The following code demonstrates how to define a hook (HOOK)


The following code is a switch command, which masks and releases ESC and is executed alternately. You can also modify VK_ESCAPE to other key codes to block other keys.


The hook function defined is:

Intercept the WM_KEYDOWN message. If the ESC key is pressed, the corresponding keyboard code is VK_ESCAPE (27), interrupt the message loop, and prevent AUTOCAD from knowing that this key press occurred.

Code - Auto/Visual Lisp: [Select]
  1. (defun _mask-esc (hwnd msg wparam lparam ti pos)
  2.      (cond ((= msg WM_KEYDOWN);;Keyboard press message
  3.             (setq code wparam)
  4.             (if (= code VK_ESCAPE)
  5.               (xdrx_hook_block_messageloop t)
  6.             )
  7.            )
  8.      )
  9.    )
  10.  

Implementation code (Switch Command):

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt ()
  2.    (defun _mask-esc (hwnd msg wparam lparam ti pos)
  3.      (cond ((= msg WM_CHAR)
  4.             (setq code wparam)
  5.             (if (= code VK_ESCAPE);;if ESC
  6.               (xdrx_hook_block_messageloop t);;Block the message and let ACAD take over
  7.             )
  8.            )
  9.      )
  10.    )
  11.    (xdrx_begin)
  12.    (xd::hook:register "_mask-esc" nil "Mask ESC");Register hook function
  13.    (if (not #xd_hook_mask_esc)
  14.      (progn
  15.        (xd::hook:enable "_mask-esc" t);;Hook function enabled
  16.        (setq #xd_hook_mask_esc t)
  17.      )
  18.      (progn
  19.        (xd::hook:enable "_mask-esc" nil);;Hook function disabled
  20.        (setq #xd_hook_mask_esc nil)
  21.      )
  22.    )
  23.    (xdrx_end)
  24.    (princ)
  25. )

=============

The above LISP code uses the XDRX-API, which can be downloaded from https://github.com/xdcad/XDrx-API

The XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message.
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net