Author Topic: shift key down  (Read 12006 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: shift key down
« Reply #15 on: October 27, 2007, 11:44:21 PM »
I'm stumped at "add a module..." so I'm starting to study VBA. Is it going to be fun? Is there a book you would recommend?

See the attached ApiUtils.zip file (contains ApiUtils.dvb), perhaps it will help. Open it via Tools -> Macro -> Load Project and then open the VBA IDE via Tools -> Macro -> Visual Basic Editor or type VBAMAN at the AutoCAD command line, load it up using the [Load ...] button, and then open the VBA IDE by hitting the [Visual Basic Editor] button.

I think it's fun but I'm weird that way. As for books, eek, I must have 30 on VB alone, though none of them are AutoCAD centric. Hmmm, perhaps Programming Visual BASIC 6.0, by Francesco Balena (don't know if it's still in print) as a first. It's well written and sports good info that is still usable today, including ADO, API calls etc. despite being kinda long in the tooth at 8 years old. Case in point, page 1203 discusses the API call I used below, even tho I initially started out by perusing some of my other books when starting this exercise.

Having said all that, if you're just starting out learning VB(A) I'd probably recommend you go VB.NET or C# instead. VB(A) has served me very well for a very long time but it's considered antiquated now by most.
« Last Edit: October 28, 2007, 07:46:27 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Joe Burke

  • Guest
Re: shift key down
« Reply #16 on: October 28, 2007, 08:22:51 AM »
Michael,

Thanks for the ApiUtils.dvb file. Yes, it helped. I have the code you posted working now.

Regarding my comment, "starting to study VBA", what I meant was try to understand how it works only so I could use the code in your first reply (apparently deleted) without further assistance. At this point I have half an idea. I need to study more.

In a more general sense, I don't feel a pressing need to learn a language beyond what I know with lisp/vlisp. On the other hand, I am concerned about the fact Autodesk failed to document/expose some new things in 2008. For instance, annotative objects in general.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: shift key down
« Reply #17 on: October 28, 2007, 08:52:40 AM »
Regarding my comment, "starting to study VBA", what I meant was try to understand how it works only so I could use the code in your first reply (apparently deleted) without further assistance.

I nuked my first pass at your challenge as it was using one of the user variables to hand off a result from VBA to LISP, which in my mind was less robust than talking directly to LISP from VBA via vl.application. However, if you want to see a variant based on using one of the user variables see the code below.

In a more general sense, I don't feel a pressing need to learn a language beyond what I know with lisp/vlisp.

As long as your content to live with those limits. I'm not. I know over a half dozen different programming languages in varying degrees, from neophyte to PFG. The knowledge and puzzle solving skills one gets from that kind of experience, in my opinion, is rather priceless if I may be so bold. Can't wait to learn more.

On the other hand, I am concerned about the fact Autodesk failed to document/expose some new things in 2008. For instance, annotative objects in general.

Call me jaded, but I expect as much from Autodesk. It's not like they started that policy with 2008.



Add this to the ApiUtils.dvb, Keyboard module --

Code: [Select]
Public Sub GetKeyStates2()

    ThisDrawing.SetVariable "useri1", _
        IIf(ApiKeyStates(vbKeyShift)   And IS_DOWN, SHIFT_KEY, 0) Or _
        IIf(ApiKeyStates(vbKeyControl) And IS_DOWN, CONTROL_KEY, 0) Or _
        IIf(ApiKeyStates(vbKeyMenu)    And IS_DOWN, ALT_KEY, 0)
   
End Sub

Add this to the LISP file --

Code: [Select]
(defun _GetKeyStates2 ( / dvbpath dvbfile macro useri1 testval  result )

    ;;  Make some modest attempts to troubleshoot
    ;;  if things go south so you can remedy ...
   
    (setq useri1 (getvar "useri1"))
   
    (setvar "useri1" (setq testval 99999))
   
    (cond
   
        (   (null
                (setq dvbpath
                    (findfile
                        (setq dvbfile "ApiUtils.dvb")
                    )
                )
            )
            (princ
                (strcat
                    "Error: Could not locate "
                    dvbfile
                    ". "
                )
            )
        )
       
        (   (vl-catch-all-error-p               
                (vl-catch-all-apply
                   '(lambda ( )
                        (vla-runmacro
                            (vlax-get-acad-object)
                            (setq macro
                                (strcat
                                    dvbpath
                                    ;;  note the 2!!
                                    "!Keyboard.GetKeyStates2"
                                )
                            )           
                        )
                    )
                )
            )
            (princ
                (strcat
                    "Error attempting to execute "
                    macro
                    "."
                )
            )
        )
       
        (   (eq testval (setq result (getvar "useri1")))
            (princ
                (strcat
                    macro
                    " failed to setvar USERI1."
                )
            )
        )
       
        (   (setq result
                ;;  return each key (shift, control, alt) with T or nil
                ;;  to indicate down (pressed) or up status respectively
                (list
                    (cons 'shift   (eq 1 (logand 1 result)))
                    (cons 'control (eq 2 (logand 2 result)))
                    (cons 'alt     (eq 4 (logand 4 result)))
                )
            )       
        )
    )
   
    ;;  reset useri1 to it's former value (play nice)
   
    (setvar "useri1" useri1)
   
    result
   
)

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
Re: shift key down
« Reply #18 on: October 28, 2007, 03:01:40 PM »
Thanks Luis,

Works great. It's comforting to have an alternative to the ExpressTools functions.

I will use your ARX. And BTW, I don't really need the Alt key option.


Good!

In case, you want to keep a copy of the Visual Studio solution for a future update or compilation, let me know.

sinc

  • Guest
Re: shift key down
« Reply #19 on: October 28, 2007, 03:20:51 PM »
On the other hand, I am concerned about the fact Autodesk failed to document/expose some new things in 2008. For instance, annotative objects in general.

Call me jaded, but I expect as much from Autodesk. It's not like they started that policy with 2008.


I don't think it's so much a policy, as something that's  hard to avoid with Autodesk's current company policies and procedures.  They can't really provide API calls until the code gets at least somewhat stable.  Also keep in mind that they have to have at least some measure of documentation written to go with the API.  Then there's the translations - Autodesk releases all their language variants at the same time, so they also need time to translate the English documentation into the 13-or-so other languages.

And judging from the issues we've seen with Annotative Text, this was another feature that still wasn't really right at release, they just released what they had when they hit their deadline.  So I think they just flat out never got a chance to work on the API.  Maybe it will be in the 2009 API.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: shift key down
« Reply #20 on: October 28, 2007, 04:47:14 PM »
I think what you're trying to say is that it's an unfortunate consequence of bean counter dictated delivery schedules.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

FengK

  • Guest
Re: shift key down
« Reply #21 on: October 30, 2007, 01:05:52 PM »
I'm looking for a function which tests for shift key down within
a routine like the ExpressTools function (acet-sys-shift-down).
It works well, returning either T or nil depending on the state of
the key. But I'd rather not depend on an ET function if there's a
generic alternative available.

Assuming it can be done, a similar test for either ctrl or alt key
down would also be welcome.

TIA for any thoughts on this.

Joe,

I also put together a vba/lisp mixed solution after some searching/reading. It is quite similar to what Michael has posted, but I'll post it anyway. Please see attached. Usage instruction included in source code.

Btw, the book I referred in the dvb file "Professional Excel Development" is where I got the code of using Windows API to determine key state. It is an excellent book.