明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2481|回复: 10

[讨论] 输入法 反应器

[复制链接]
发表于 2016-4-18 09:50 | 显示全部楼层 |阅读模式
(vl-load-com)


         (VLR-editor-Reactor nil  
                 '(
                    (:vlr-commandWillStart . command-will-start)
                        (:vlr-commandEnded . command-will-ENDED)
                  ) )  



(defun command-will-start (reactor command-list)

  (cond
  (   (member (car command-list) '( "DDEDIT" "MTEDIT"  ))

          (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Shell")  'Sendkeys       "{CAPSLOCK}"     )
      
  )
          
          
          
  )
)

(defun command-will-ENDED (reactor1 command-list1)

  (cond
  ( (member (car command-list1) '("DDEDIT" "MTEDIT"  ))      
          (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Shell")  'Sendkeys       "{CAPSLOCK}"     )  
          (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Sleep 2000")      )
   )
          
          
          
  )
)



有什么方法能够检测目前的大小写状态呢?
发表于 2016-4-18 13:45 | 显示全部楼层
要用API,lisp应该不好搞
发表于 2016-4-18 15:03 | 显示全部楼层
使用 DynamicWrapperX 来调用系统API

(setq :VK_CAPITAL 20)
(setq $DWrapX  (vlax-create-object "DynamicWrapperX"))
(vlax-invoke $DWrapX 'GetKeyState :VK_CAPITAL)
 楼主| 发表于 2016-4-18 15:07 | 显示全部楼层
elitefish 发表于 2016-4-18 15:03
使用 DynamicWrapperX 来调用系统API

(setq :VK_CAPITAL 20)

看得不是很懂,api没了解过[em0]
发表于 2016-4-18 15:16 | 显示全部楼层
可以参考下这篇文章
http://bbs.mjtd.com/forum.php?mo ... D108%26typeid%3D108

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2016-4-18 15:24 | 显示全部楼层
elitefish 发表于 2016-4-18 15:16
可以参考下这篇文章
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=85724&extra=page%3D1%26filter% ...

看到了,错误: ActiveX 服务器返回错误: 未知名称: "GETKEYSTATE"。

调用(vlax-invoke wrap 'MessageBoxW hCAD "Hello,DynWrap" "Test for API" 2) 可以显示。
 楼主| 发表于 2016-4-18 15:25 | 显示全部楼层
elitefish 发表于 2016-4-18 15:16
可以参考下这篇文章
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=85724&extra=page%3D1%26filter% ...

看到了,错误: ActiveX 服务器返回错误: 未知名称: "GETKEYSTATE"。

调用(vlax-invoke wrap 'MessageBoxW hCAD "Hello,DynWrap" "Test for API" 2) 可以显示。
发表于 2016-4-18 15:57 | 显示全部楼层
漏了一句 申明

(vlax-invoke $DWrapX 'Register "user32.dll" "GetKeyState" "i=l" "r=n")
 楼主| 发表于 2016-4-18 16:35 | 显示全部楼层
elitefish 发表于 2016-4-18 15:57
漏了一句 申明

(vlax-invoke $DWrapX 'Register "user32.dll" "GetKeyState" "i=l" "r=n")

谢谢,粗略的改了一下,不知是否有bug

(DEFUN getcaps()


  (setq *APP (vlax-get-acad-object))
  (setq *DOC (vla-get-ActiveDocument *APP))
  (setq hCAD (vla-get-hwnd *APP))
  (setq hDOC (vla-get-hwnd *DOC))
  (setq wrap (vlax-create-object "DynamicWrapperX"))
; (vlax-invoke wrap 'Register "user32.dll" "MessageBoxW" "i=hwwu" "r=l")
; (vlax-invoke wrap  'GetKeyState  :VK_CAPITAL)
(vlax-invoke wrap 'Register "user32" "GetKeyState" "i=l" "r=l")
(vlax-invoke wrap  'GetKeyState  :VK_CAPITAL)

)





(DEFUN getIMS()
  (setq *APP (vlax-get-acad-object))
  (setq *DOC (vla-get-ActiveDocument *APP))
  (setq hCAD (vla-get-hwnd *APP))
  (setq hDOC (vla-get-hwnd *DOC))
  (setq wrap (vlax-create-object "DynamicWrapperX"))
; (vlax-invoke wrap 'Register "user32.dll" "MessageBoxW" "i=hwwu" "r=l")
; (vlax-invoke wrap  'GetKeyState  :VK_CAPITAL)
(vlax-invoke wrap 'Register "user32" "GetKeyboardLayout" "i=l" "r=l")
(if (= (vlax-invoke wrap  'GetKeyboardLayout 0 ) -534771708)
(setq ims "SOGOU")

(if (= (vlax-invoke wrap  'GetKeyboardLayout 0 ) 67700740)
(setq ims "ENG")

)
)
ims
)

(DEFUN setims()
(setq *APP (vlax-get-acad-object))
  (setq *DOC (vla-get-ActiveDocument *APP))
  (setq hCAD (vla-get-hwnd *APP))
  (setq hDOC (vla-get-hwnd *DOC))
  (setq wrap (vlax-create-object "DynamicWrapperX"))
; (vlax-invoke wrap 'Register "user32.dll" "MessageBoxW" "i=hwwu" "r=l")
; (vlax-invoke wrap  'GetKeyState  :VK_CAPITAL)
(vlax-invoke wrap 'Register "user32" "GetKeyboardLayout" "i=l" "r=l")
(vlax-invoke wrap 'Register "user32" "ActivateKeyboardLayout" "i=l" "r=l")
(if (/= (vlax-invoke wrap  'GetKeyboardLayout 0 ) -534771708)
(vlax-invoke wrap  'ActivateKeyboardLayout -534771708 )
)
)

(vl-load-com)
         (VLR-editor-Reactor nil  
                 '(
                    (:vlr-commandWillStart . command-will-start)
                        (:vlr-commandEnded . command-will-ENDED)
                  ) )
(defun command-will-start (reactor command-list)
  (cond
  (   (member (car command-list) '( "DDEDIT" "MTEDIT"  "eattedit")) ;指令要大写
(IF  (=  (getcaps) 1)
       (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Shell")  'Sendkeys   "{CAPSLOCK}"     )
  )
           (setims)
      
  )
)
)
(defun command-will-ENDED (reactor1 command-list1)
  (IF (=  (getcaps) 0)
            (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Shell")  'Sendkeys       "{CAPSLOCK}"     )  
          ; (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Sleep 500")      )
   )
       
)

点评

很有用,可以识别正在使用的输入法了  发表于 2022-6-9 16:20

评分

参与人数 1明经币 +1 收起 理由
自贡黄明儒 + 1 很给力!

查看全部评分

 楼主| 发表于 2016-4-18 16:44 | 显示全部楼层
暗夜贵族 发表于 2016-4-18 16:35
谢谢,粗略的改了一下,不知是否有bug

(DEFUN getcaps()

加个锁定大写开关
(vlr-dwg-reactor
    nil
    '((:vlr-beginsave . SAVE) )
  )
(DEFUN SAVE(OBJ REACT)
  (IF (=  (getcaps) 0)
            (Vlax-Invoke-Method  (Vlax-Get-Or-Create-Object "WScript.Shell")  'Sendkeys       "{CAPSLOCK}"     )  
            )
)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-19 08:54 , Processed in 1.098089 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表