Author Topic: Caps Lock  (Read 18562 times)

0 Members and 1 Guest are viewing this topic.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Caps Lock
« on: April 09, 2012, 03:52:12 PM »
Needed this the other day for something that I was working on.  Couldn't find anything online so I cobbled this together.  Why Autocad doesn't have this property?

Code: [Select]
;; Toggle = T/nil - T = Turns ON CAPS / nil = Turns OFF CAPS
(defun CAPSLOCK (Toggle / MS-Word)
;; Get the word application
(if (setq MS-Word (vlax-get-or-create-object "Word.Application"))
;; If word exists set
(progn
;; Check for CAPS LOCK
(cond
;;Toggle is T and CAPS LOCK is off
((and (= Toggle T)(= (vlax-get MS-Word 'CapsLock) 0))
(vlax-invoke-method  (vla-getInterfaceObject (vlax-get-acad-object) "WScript.Shell") 'SendKeys "{CAPSLOCK}")
)
;;Toggle is nil and CAPS LOCK is on
((and (= Toggle nil)(= (vlax-get MS-Word 'CapsLock) -1))
(vlax-invoke-method  (vla-getInterfaceObject (vlax-get-acad-object) "WScript.Shell") 'SendKeys "{CAPSLOCK}")
)
)
;; Exit word
(vlax-invoke-method MS-Word 'Quit)
;; Release object
(vlax-release-object MS-Word)
;; Quite exit
(princ)
)
;; Send nil
nil
)
)
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: Caps Lock
« Reply #1 on: April 09, 2012, 05:26:22 PM »
Seems useful, but I'm not advanced enough to know how to use it!  I used (capslock T) and (capslock nil) successfully in CAD, but I don't know about Word usage.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Caps Lock
« Reply #2 on: April 09, 2012, 05:27:48 PM »
I wouldn't have thought to use MSWord, nice one Tim  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Caps Lock
« Reply #3 on: April 09, 2012, 05:29:28 PM »
I wouldn't have thought to use MSWord, nice one Tim  :-)
x2!
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Caps Lock
« Reply #4 on: April 09, 2012, 05:43:45 PM »
FWIW - For fun:

Code - vb.net: [Select]
  1. Imports Autodesk.AutoCAD.ApplicationServices
  2. Imports Autodesk.AutoCAD.DatabaseServices
  3. Imports Autodesk.AutoCAD.EditorInput
  4. Imports Autodesk.AutoCAD.Runtime
  5.  
  6. Imports System
  7.  
  8. <Assembly: CommandClass(GetType(Foo.Foo))>
  9.  
  10. Namespace Foo
  11.  
  12.     Public Class Foo
  13.  
  14.         <LispFunction("CapsLock-p")> _
  15.         Public Function CapsLock_P(ByVal args As ResultBuffer)
  16.             If My.Computer.Keyboard.CapsLock = True Then
  17.                 Return True
  18.             Else
  19.                 Return Nothing
  20.             End If
  21.         End Function
  22.  
  23.     End Class
  24.  
  25. End Namespace
  26.  

** Returns T if CapsLock is on, Nil if off. Tested using Civil 3D 2011, 2012.
"How we think determines what we do, and what we do determines what we get."

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Caps Lock
« Reply #5 on: April 09, 2012, 05:52:29 PM »
Seems useful, but I'm not advanced enough to know how to use it!  I used (capslock T) and (capslock nil) successfully in CAD, but I don't know about Word usage.

MS Office applications (some of them) have a "CapsLock" property that can be checked, Autocad does not.  I couldn't find any good references (dll) that had a good way of checking for CapsLock.  This was the best "lisp" only way that I could come up with (after almost 2 days searching / playing)

If some one has a better way, I would love to see it.  (lisp only, I not very versed in much else   :roll:
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

BlackBox

  • King Gator
  • Posts: 3770
Re: Caps Lock
« Reply #6 on: April 09, 2012, 06:19:21 PM »
Tim - I've successfully tested an enhanced version of the LispFunction posted above (now simply named "CapsLock"), and am able to successfully toggle the CapsLock and not just test for current status.

Before I post, I just have to revise my IF statement to allow for user-specified On (T) / Off (Nil), as currently either T or Nil as Argument will toggle (which is not what we want). I will post back source and compiled code for your use.
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Caps Lock
« Reply #7 on: April 09, 2012, 06:40:22 PM »
** Edit - Code updated in this post.


Update: "CapsLock" LispFunction

When called without an argument, the CapsLock status is returned as T (True) for ON, or Nil for OFF.

When called with a single argument as T (True) the CapsLock status is evaluated, and turned ON if presently OFF. Single argument as Nil evaluates the current CapsLock status, and turns OFF is presently ON.


Here's the revised source code for those, like me, that prefer to compile yourself:


Code - vb.net: [Select]
  1. ' Code updated in another post


... Here's the compiled code (attached). I compiled to .NET 3.5 for use in 2010 and newer drawings. Please let me know if you have any problems (I don't usually distribute to others outside of my work).


HTH
« Last Edit: April 10, 2012, 12:40:02 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

GDF

  • Water Moccasin
  • Posts: 2081
Re: Caps Lock
« Reply #8 on: April 09, 2012, 06:55:00 PM »
Good one Tim, I'll add it to my ANNO routine. To make sure the caps are always on when inserting text. Thanks for sharing it.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Caps Lock
« Reply #9 on: April 09, 2012, 07:29:34 PM »
Update: "CapsLock" LispFunction

When called without an argument, the CapsLock status is returned as T (True) for ON, or Nil for OFF.

When called with a single argument as T (True) the CapsLock status is evaluated, and turned ON if presently OFF. Single argument as Nil evaluates the current CapsLock status, and turns OFF is presently ON.

Here's the revised source code for those, like me, that prefer to compile yourself:

... Here's the compiled code (attached). I compiled to .NET 3.5 for use in 2010 and newer drawings. Please let me know if you have any problems (I don't usually distribute to others outside of my work).

HTH

This is great! ( i haven't tried it yet) , I will try when I get back to work tomorrow.  Maybe we can get a complete set exposed  to autocad caps, num, scroll?  A total package would be a great resource.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

BlackBox

  • King Gator
  • Posts: 3770
Re: Caps Lock
« Reply #10 on: April 09, 2012, 07:42:15 PM »
I'm glad this is of interest to you, Tim.

Funny enough, it dawned on me after posting that the other locks may be of use too! I've already brought my laptop home to tinker. LoL if I get enough together I may just incorporate this into my VLX-* (Visual Lisp Xpanded) LispFunction library.
"How we think determines what we do, and what we do determines what we get."

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Caps Lock
« Reply #11 on: April 09, 2012, 07:53:15 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Caps Lock
« Reply #12 on: April 09, 2012, 08:37:33 PM »
It would be great to use in a reactor for text and such (my plan anyway).  I hate having to go from autocad to outlook and start typing and there is an entire email in CAPS.  This has been a small thorn in a lisp developer's side for years.  It would be nice to have a great solutions.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Rod

  • Newt
  • Posts: 185
Re: Caps Lock
« Reply #13 on: April 10, 2012, 02:31:17 AM »
Two options I can think of is
doslibs dos_capslock see http://www.en.na.mcneel.com/doslib/system_functions/dos_capslock.htm
for setting the caplock state
Eg. (dos_capslock nil) (dos_capslock T)

and the express utility (acet-sys-keystate keycode) see http://www.afralisp.net/archive/lisp/acet-utils.htm
Eg. (acet-sys-keystate 14) for checking the capslock state
I'm not in front of autocad now so you will have to check yourself.
Rod

"All models are wrong, some models are useful" - George Box

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Caps Lock
« Reply #14 on: April 10, 2012, 07:16:48 AM »
Two options I can think of is
doslibs dos_capslock see http://www.en.na.mcneel.com/doslib/system_functions/dos_capslock.htm
for setting the caplock state
Eg. (dos_capslock nil) (dos_capslock T)

and the express utility (acet-sys-keystate keycode) see http://www.afralisp.net/archive/lisp/acet-utils.htm
Eg. (acet-sys-keystate 14) for checking the capslock state
I'm not in front of autocad now so you will have to check yourself.
Rod

I know about both of those options, but we don't have Doslib here (stuff like that is prohibited  :ugly:)
The express tools is a great idea but you can not ensure that everyone has the express tools loaded, and it takes an act of Congress to get things loaded from IT around here.  So I try not to develop applications around them.  The express tools is a great option, it should be part of the vlsip com.
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016