Let Lisp to Control the WINDOWS message loop (inject hooks into ACAD) and monitor keyboard and mouse messages.Regarding the message loop of the WINDOWS system, you can search online and refer to the literature.
All software in the WINDOWS system interacts with the system through the message loop. When we press the keyboard or move the mouse, the WINDOWS system will send the message to AUTOCAD, and AUTOCAD will accept the message processing and return the information to the system.
The system keyboard message received by AUTOCAD can be intercepted through the hook related functions of ARX. After the application process, the message can continue to be passed to AUTOCAD for subsequent operations, or it can be intercepted so that AUTOCAD does not know that this "message" has come, and AUTOCAD can also You cannot continue to respond to messages and operate.
The general hook function is defined as follows:
BOOL HOOK(MSG *pMsg)
{
switch(pMsg->message){
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if(...)
{
return TRUE; // TRUE intercepts the message and does not allow AUTOCAD to continue processing.
}
break;
}
return FALSE; // Return FALSE, AUTOCAD can continue to accept the message
}
Can A/VLISP also intercept message processing? No, LISP does not provide such a function.
The above operations are completed through the custom functions provided by the XDRX API to LISP.
The "hook" related functions provided by the API are:
xdrx-hook-register
xdrx-hook-enable
xdrx-hook-status
xdrx-hook-remove
xdrx-hook-tracemouse
xdrx-hook-block-messageloop
xdrx-system-keystate
xdrx-system-ctrl-down
xdrx-system-ctrl-shift-down
xdrx-system-ctrl-alt-shift-down
xd::hook:register
xd::hook:enable
xd::hook:remove
The function of the xdrx-hook-block-messageloop function is equivalent to the return TRUE mentioned above, and the termination message is continued to AUTOCAD.
The typical hook callback function structure of LISP is as follows:
(defun hook
(hwnd msg wparam lparam time pos
) ;|
hwnd -- window handle
msg --- message
wparam -- main parameter
lparam ---- second parameter
time ------- time of occurrence
pos ------- mouse screen coordinates
|;
(cond ((= msg WM_KEYUP
) ; key up )
((= msg WM_KEYDOWN) ;Key pressed
)
((= msg WM_SYSKEYDOWN)) ;System key pressed
((= msg WM_CHAR)
)
((= msg WM_MOUSEWHEEL) ; Turn the wheel
)
((= msg WM_LBUTTONUP) ;The left mouse button pops up
)
((= msg WM_LBUTTONDOWN) ;Left mouse button pressed
)
((= msg WM_LBUTTONDBLCLK) ;Double left mouse button click
)
((= msg WM_RBUTTONUP) ; Right mouse button pops up
)
((= msg WM_RBUTTONDOWN) ;Right mouse button pressed
)
((= msg WM_RBUTTONDBLCLK) ;right mouse button double click
)
((= msg WM_MBUTTONUP) ;Middle mouse button pops up
)
((= msg WM_MBUTTONDOWN) ;Middle mouse button pressed
)
((= msg WM_MBUTTONDBLCLK) ;Middle mouse button double click
)
((= msg WM_MOUSEMOVE) ;mouse movement
)
((= msg WM_PAINT) ;Screen drawing
)
((= msg WM_HOTKEY) ;Hotkey
)
((= msg WM_INPUT) ;Input
)
((= msg WM_VSCROLL) ;Screen scrolling
)
)
)
The following is a program description of capturing mouse hotkeys through OpenDCL:
The following program will write the keyboard keys, including CTRL, SHIFT, ALT and letter key combinations, into the text box in real time.
Here is the implementation code: '("YWt6A2YXAAAh3q+ZBuKTJsUwKi9qI/1OYh86Xl9frzx8ON3ysnVmUlK6Jtb29vdoaHSydoxmezrS"
"zu26uLTmFh8Xn02Pa1XdcwgC/mE+nNVNeOsP4U0OYRVmUFYev6KaoEeVQohAGZHLqZss4OA1hb32"
"XvRmZK96v4RQkzt03ZY5fKlu6ghxxE9+Yf6XHN46AIvKxNonZOif+jIW6Ndfursu3cocrGlo7T+X"
"97byUBdLdXA3AXEk3qO42tk1KGTJFxNPUIOZ20EUKInmSx8nrRtSWBtSX9NoZxFIgOwcQxgusqYS"
"5KHzYX/DJU/keNTfAla+glsQ9HC15/hPVu2ralRpOJjZ1u1W+p0sbZiamORv/ZTg5rEiQE8orfOD"
"JkIec85jq9xjPRbrbXK3Jjw4JZswHzqklMm1nIjBy9a4IgjI07Lwy+U0hcJBiodBxNI8I1uCtOAR"
"nIv8jjW8sXeBWgWd+oNASYAbmTllLEkuElspmdlIGcyh37bPbjTvm3HQ6y7Fk+PA6EXON2Alc9IZ"
"MOvg7K7zNdZxnPRCObuXLnAAaz4nGRHJQyoVkglnU77Tp3ArOsVyxpwty+6b6hpH9rWcwDGipSeT"
"7fKJ5dQtMfensXZB37ZBWIL2jj28W+rnX6kXfBOWunDHBXMledoDNuBp3lAklUwHN29gytyahdBN"
"ojGdffpHsetqm6XKsVQFQtqPd2UxFALtsKc/jZkSgbigKaSxaVVw54vh9hmhko3nh+FTOBkOY9Oh"
"F4XhrJ25F0E517zwbxBdAvpOApCGxpUcDUilqlD01t0MsLZjro9VTY5+KfDMVVlbwU8ab+AXucpS"
"XbKXGQROA+YgMkHYGWmH5VoC5A78Tq2XUJ/NUCLfdQIyGgCmbJUw96bW744QN742SL/Cdpc7Tlga"
"7AiW3xRzuvhuH7llCyh5wq40Jhii3/StZFHfJRhAlTD7E7GyIdBww8+DAK+F9O0hUWOnNZnW3Idw"
"I8fRD0OrI+6OYMyB4IitP4gVNimIR6CabbaoY/nw6r3TXU0me2MX34PEC9oO/6o11/moId1gJXKK"
"LPEWIEMM1DkSndf5AImaqx2Tq72C65ou8TUmUYv2UzFDfHgE1zla0WBHq13Ej6qdRIyUH6clPYtG"
"eckEor8E1zkKB5QvFN7pBAYBk9FcSWEWshybuytoVdGRhauciBQBoQWrtDTBgccIJionCicagcuo"
"JuonysMU7zviFU3Z1jkM98QpS4G5gQa6nyj1ySaaW89QlG+PKnEDg39nvMRW")
)
(xd::hook:remove "_hook-1")
(dcl
-form
-close hotkey
-odcl
/Form1
) )
(defun c:hotkey
-odcl
/Form1#OnClose
(UpperLeftX UpperLeftY
/) (xd::hook:remove "_hook-1")
(dcl
-form
-close hotkey
-odcl
/Form1
) )
(defun c:hotkey
-odcl
/Form1#OnCancelClose
(Reason
/) (xd::hook:remove "_hook-1")
(dcl
-form
-close hotkey
-odcl
/Form1
) )
(defun c:hotkey
-odcl
/Form1#OnCancel
(/) (xd::hook:remove "_hook-1")
(dcl
-form
-close hotkey
-odcl
/Form1
) )
(defun c:var1#OnSetFocus
(/) (setq #var
-name
(dcl
-Control
-GetProperty var1
"VarName")) )
(defun c:var2#OnSetFocus
(/) (setq #var
-name
(dcl
-Control
-GetProperty var2
"VarName")) )
(defun c:var3#OnSetFocus
(/) (setq #var
-name
(dcl
-Control
-GetProperty var3
"VarName")) )
(defun c:var4#OnSetFocus
(/) (setq #var
-name
(dcl
-Control
-GetProperty var4
"VarName")) )
(defun _hook
-1 (hwnd msg wparam lparam time pos
) (and (dcl
-Form
-IsActive hotkey
-odcl
/Form1
) (cond ((= msg WM_KEYDOWN
) (< wparam 91)
(/= "" #var-name)
)
((xdrx-system-ctrl-down)
(dcl-Control-SetText
)
)
((xdrx-system-shift-down)
(dcl-Control-SetText
)
)
((xdrx-system-ctrl-shift-down)
(dcl-Control-SetText
)
)
((xdrx-system-ctrl-alt-shift-down)
(dcl-Control-SetText
(strcat "CTRL+ALT+SHIFT+" txt
) )
)
)
(xdrx-hook-block-messageloop t) ;;Block this message and let AUTOCAD continue processing.
)
)
)
(T)
)
)
)
(xd::hook:register "_hook-1" t "dd")
(dcl-project-import odcl-data "123456")
(dcl-Form-Show hotkey-odcl/Form1)
)
=============
The above LISP code uses the XDRX-API, which can be downloaded from
https://github.com/xdcad/XDrx-APIThe XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.
Modify message