Author Topic: define accelarator keys using lisp  (Read 8053 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
define accelarator keys using lisp
« on: August 09, 2006, 05:39:57 PM »
Is there a way to define accelarator keys using lisp? Like changing F4 to a snap?

thanks,

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Patrick_35

  • Guest
Re: define accelarator keys using lisp
« Reply #1 on: August 10, 2006, 04:21:04 AM »
Hi
Yes, you can use or look the lisp aliasedit from expresstools

@+

LE

  • Guest
Re: define accelarator keys using lisp
« Reply #2 on: August 10, 2006, 09:26:21 AM »
Is there a way to define accelarator keys using lisp? Like changing F4 to a snap?

As far as I know - nope -

ronjonp

  • Needs a day job
  • Posts: 7529
Re: define accelarator keys using lisp
« Reply #3 on: August 10, 2006, 11:27:50 AM »
Darn.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: define accelarator keys using lisp
« Reply #4 on: August 10, 2006, 06:12:15 PM »
No sarcasim (I am drop dead serious): This is a wonderfull post Ron! Outstanding subject title, clean/clear question, overall nice in tone...Many people could learn from the way this subject was handed by you.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7529
Re: define accelarator keys using lisp
« Reply #5 on: August 10, 2006, 08:06:22 PM »
Gosh  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: define accelarator keys using lisp
« Reply #6 on: August 10, 2006, 09:56:39 PM »
I can only do this by other software : autohook.
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: define accelarator keys using lisp
« Reply #7 on: August 10, 2006, 10:21:46 PM »
.. and <our own> Chuck Gabriel's  HotKeys .. an excellent product ; and free, thanks to his generosity. The link has been posted in one of Chucks posts here.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

psuchewinner

  • Guest
Re: define accelarator keys using lisp
« Reply #8 on: August 11, 2006, 07:31:45 AM »
The only way that I have seen it done is by a menu.  See below.  My guess is that you could write it and initiate it with Lisp.

["F1"]'graphscr
["F2"]_endp
["F3"]_nea
["F4"]_int
["F5"]_per
["F6"]_ins
["F7"]_mid
["F9"]_cen
["F11"]_quad
["F12"]_tan
[SHIFT+"F1"]'textscr
[SHIFT+"F2"]'zoom;w
[SHIFT+"F3"]'zoom;p
[SHIFT+"F4"]'properties
[SHIFT+"F5"]'layer
[SHIFT+"F6"]'ddim

Nothing Earth Shaking but it works.  Sometimes simplicity is good.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: define accelarator keys using lisp
« Reply #9 on: August 11, 2006, 07:47:46 AM »
.. and <our own> Chuck Gabriel's  HotKeys .. an excellent product ; and free, thanks to his generosity. The link has been posted in one of Chucks posts here.

hotkeys is a very good software, and it even afford the code, great.

I define some key by it, but I find that "TAB" cant be define, which I often define in autohook to do the ortho function which F8 does,

and I dont know how to defin "F1" as the function as "F8"--ortho in Hotkeys.

http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

Chuck Gabriel

  • Guest
Re: define accelarator keys using lisp
« Reply #10 on: August 11, 2006, 08:40:21 AM »
Thanks for the kind words Kerry.

yuangiu - If you want the tab key to toggle orthomode, you will have to edit your keys file manually because of the way the keys editor interprets the tab key.

Add a key with a modifiers value of zero, a virtual key value of 9, and (setvar "ORTHOMODE" (if (zerop (getvar "ORTHOMODE")) 1 0)) for the command value.

It sounds like autohook lets you actually map one key on the keyboard to be interpreted as an entirely different key.  HotKeys doesn't work quite that way.  It allows you to have AutoCAD execute a macro when you press a key.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: define accelarator keys using lisp
« Reply #11 on: August 12, 2006, 09:32:01 AM »
yuangiu - If you want the tab key to toggle orthomode, you will have to edit your keys file manually because of the way the keys editor interprets the tab key.
Add a key with a modifiers value of zero, a virtual key value of 9, and (setvar "ORTHOMODE" (if (zerop (getvar "ORTHOMODE")) 1 0)) for the command value.
It sounds like autohook lets you actually map one key on the keyboard to be interpreted as an entirely different key.  HotKeys doesn't work quite that way.  It allows you to have AutoCAD execute a macro when you press a key.

Thank you, Chuck, It DOES WORK, very wonderful.
now I set in the xml for modifiers 0 and key 9 and then the tab is define:),
and the (setvar "ORTHOMODE" (if (zerop (getvar "ORTHOMODE")) 1 0))  is really work in transparent mode, very nice, how can it work, it is hard to do it, can lisp be executed transparently in command, I never try it before.

autohook is a special software just for autocad, maybe it is also wrote in arx, it is not just map key function I think, it could also execute a serial command, just like in autohook, I define ortho to tab by define tab ('^o  ), the bracket is not include, then it works, but autohook is a shareware.

Thanks again.
« Last Edit: August 12, 2006, 09:36:42 AM by yuanqiu »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: define accelarator keys using lisp
« Reply #12 on: August 12, 2006, 10:03:58 AM »
Gosh  :-)

No dont be shy. Own up to it. It was good. Now if you want to step it up to the next level...Check here and improve your methods for asking questions (which will result in more, faster, and beter answers for you). [ http://www.catb.org/~esr/faqs/smart-questions.html ]  ...Kinda makes you want to go back and fix a few of ``your'' previous questions huh? (That was a general statment, i wasnt saying that you personaly asked bad questions up untill now, im just trying to say something like: ``if we could all take the knowledge we obtain 'today' and apply that to previous encounters...'')

Now go and read that link and ask better questions and get better answers faster.

Good job Ron. Later,
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: define accelarator keys using lisp
« Reply #13 on: August 13, 2006, 09:45:48 AM »
Hi, chuck

When I define the tab key as
- <HotKey>
  <Modifiers>0</Modifiers>
  <VirtualKey>9</VirtualKey>
  <Command>(setvar "ORTHOMODE" (if (zerop (getvar "ORTHOMODE")) 1 0))</Command>
  </HotKey>

It does work transparently in some command, such as "LINE", but when in some other command, such as "Move", it exit.

How can I define it to be more like F8.

Thank you.
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: define accelarator keys using lisp
« Reply #14 on: August 13, 2006, 04:43:15 PM »
Try this :

<Command>'ORTHOMODE (if (zerop (getvar "ORTHOMODE")) 1 0) </Command>

note the single quote to start
and the space to end
.

duh, FATFINGERSPELLING.
« Last Edit: August 13, 2006, 05:08:56 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: define accelarator keys using lisp
« Reply #15 on: August 13, 2006, 08:19:48 PM »
Thank you, Kerry~
It works, I will try to find more funny in this software, great.
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: define accelarator keys using lisp
« Reply #16 on: July 06, 2009, 08:22:06 AM »
psuchewinner 's suggestion is very good, but I have not familiar with menu file's structure before.

These few days, I study some, and with the help of my friend, mccad and lazybone.

http://www.mjtd.com/BBS/dispbbs.asp?boardid=3&replyid=9664&id=18715&page=1&skin=0&landlord=0&Star=1

http://www.mjtd.com/BBS/dispbbs.asp?boardid=3&replyid=82428&id=18715&page=1&skin=0&landlord=0&Star=2

http://www.mjtd.com/BBS/dispbbs.asp?boardid=3&replyid=13016&id=76655&page=1&skin=0&landlord=0&Star=1

http://www.mjtd.com/BBS/dispbbs.asp?boardid=3&replyid=13016&id=76655&page=1&skin=0&landlord=0&Star=2

I feel it do can define function key by lisp, just like psuchewinner said.

The following code is use to define the function keys, such as F1 simulate F8's function. It use the ACCELERATORS of menu file.
This code use mccad and lazybone's function to load a menu file, and what I do is only to define a dynamic temporary mnu file.

But I dont know how to define "TAB" key, "Ctrl+1" key, I hope you could help me.

Code: [Select]
;;This code is based on mccad and lazybone's code
;;http://www.mjtd.com/BBS/dispbbs.asp?boardid=3&replyid=8516&id=18715&page=1&skin=0&landlord=0&Star=2
;;Load the custom menu file to the last but one item
;;the menu name is test.mnu,MENUGROUP=MYTEST
;;based on the upper code, qjchen add the dynamic mnu file generation
;;How to use: Load this function, and it automatic load "ldmu", which is to load menu,  if you want to unload this menu, pls use "uldmu"
;; The definition of the shortcut
;;F1:ortho switch(like F8, I dont know how to write the mnu file with "^L", so I have to use Lisp, thanks to Chuck Gabriel for this lisp code)
;;F2-F5: for zoom
;;ctrl+w:3dorbit
;;ctrl+e:ellipse (this two function is for the learing of ctrl)

;;Load menu file, by mccad and lazybone
(defun c:ldmu (/ pre_filedia CNT)
  (setq pre_filedia (getvar "filedia"))
  (setvar "filedia" 0)
  (command "menuload" (qjchentempmnu))
  (setq CNT 1)
  (while (menucmd (strcat "P" (itoa CNT) ".1=?"))
    (setq CNT (1+ CNT))
  )
  (if (> CNT 1)
    (setq CNT (- CNT 1))
    (setq CNT 1)
  )
  (menucmd (strcat "P" (itoa CNT) "=+MYTEST.pop1"))
  (setvar "filedia" pre_filedia)
  (princ)
)
;;UnLoad menu file, by mccad and lazybone
(defun c:uldmu (/ pre_filedia)
  (setq pre_filedia (getvar "filedia"))
  (setvar "filedia" 0)
  (command "menuunload" "MYTEST")
  (setvar "filedia" pre_filedia)
  (princ)
)

;; dynamic menu file generation, by qjchen
(defun qjchentempmnu(/ mnu_name f)
  (setq mnu_name (strcat (getenv "temp") "\\test" ".mnu")
f (OPEN mnu_name "w")
  )
  (write-line "***MENUGROUP=MYTEST" f)
  (write-line "***POP1" f)
  (write-line "**Alias" f)
  (write-line "[/MMyDraw]" f)
  (write-line "ID_Ellipse [/EEllipse]^c^cEllipse" f)
  (write-line "***ACCELERATORS" f)
  (write-line "[\"F2\"]'_zoom _w" f)
  (write-line "[\"F3\"]'_zoom _p" f)
  (write-line "[\"F4\"]'_zoom _e" f)
  (write-line "[\"F5\"]'_pan" f)
  (write-line "ID_Ellipse [CONTROL+\"E\"]" f)
  (write-line "[CONTROL+\"w\"]'3DORBIT" f)
  (write-line "[\"F1\"](setvar \"ORTHOMODE\" (if (zerop (getvar \"ORTHOMODE\")) 1 0))(princ)" f)
  (close f)
  mnu_name
)

(c:ldmu)






http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)