curious why this *sometimes* works

Discussion in 'AutoCAD' started by Mark Propst, Aug 7, 2003.

  1. Mark Propst

    Mark Propst Guest

    I would think it would *always* work or *never* work, but sometimes it does
    and sometimes it doesn't and I can't figure out the pattern of what else is
    affecting it.

    its in ThisDrawing class in Acad.dvb file and is thus always
    loaded(supposedly).
    code adapted from various posts here in the past,
    sorry I don't have the original authors names handy to acknowledge - you
    know who you are - and only I am to blame for the current malfeasant version

    Option Explicit
    Private Const VK_CAPITAL = &H14
    Private Type KeyboardBytes
    kbByte(0 To 255) As Byte
    End Type
    Private kbArray As KeyboardBytes
    Private Declare Function GetKeyState Lib "user32" _
    (ByVal nVirtKey As Long) As Long
    Private Declare Function GetKeyboardState Lib "user32" _
    (kbArray As KeyboardBytes) As Long
    Private Declare Function SetKeyboardState Lib "user32" _
    (kbArray As KeyboardBytes) As Long
    Private Declare Function GetForegroundWindow Lib "user32" () As Long

    Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
    Select Case UCase(CommandName)
    Case UCase("mtext"), UCase("text"), UCase("mtedit"), UCase("dtext"),
    UCase("ddedit"), UCase("ddatte"), UCase("ET"), UCase("dt")
    StartText
    End Select
    End Sub

    Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    Select Case CommandName
    Case UCase("mtext"), UCase("text"), UCase("mtedit"), UCase("dtext"),
    UCase("ddedit"), UCase("ddatte"), UCase("et"), UCase("dt")
    TextDone
    End Select
    End Sub

    Private Sub StartText()
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = 1
    SetKeyboardState kbArray
    End Sub
    Private Sub TextDone()
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = 0
    SetKeyboardState kbArray
    End Sub

    it's supposed to set caps on at any command that requires 'typing' in the
    acad editor and then turn it off so when I post here all my dumb questions
    you guys don't yell at me for yelling at you!
    :)

    some other condition must be affecting whether it works or not but I can't
    figure out what that is.
    Mark
     
    Mark Propst, Aug 7, 2003
    #1
  2. Sometimes it works turning caps _on_, or sometimes fails to turn caps _off_?

    Autodesk, in their "wisdom", saw fit to forget to include a CommandCancelled
    event. So if you cancel one of those commands, caps will be left on.


    --
    R. Robert Bell, MCSE
    www.AcadX.com


    "Mark Propst" <mark-at-atreng-dot-com> wrote in message
    | I would think it would *always* work or *never* work, but sometimes it
    does
    | and sometimes it doesn't and I can't figure out the pattern of what else
    is
    | affecting it.
    |
    | its in ThisDrawing class in Acad.dvb file and is thus always
    | loaded(supposedly).
    | code adapted from various posts here in the past,
    | sorry I don't have the original authors names handy to acknowledge - you
    | know who you are - and only I am to blame for the current malfeasant
    version
    |
    | Option Explicit
    | Private Const VK_CAPITAL = &H14
    | Private Type KeyboardBytes
    | kbByte(0 To 255) As Byte
    | End Type
    | Private kbArray As KeyboardBytes
    | Private Declare Function GetKeyState Lib "user32" _
    | (ByVal nVirtKey As Long) As Long
    | Private Declare Function GetKeyboardState Lib "user32" _
    | (kbArray As KeyboardBytes) As Long
    | Private Declare Function SetKeyboardState Lib "user32" _
    | (kbArray As KeyboardBytes) As Long
    | Private Declare Function GetForegroundWindow Lib "user32" () As Long
    |
    | Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
    | Select Case UCase(CommandName)
    | Case UCase("mtext"), UCase("text"), UCase("mtedit"), UCase("dtext"),
    | UCase("ddedit"), UCase("ddatte"), UCase("ET"), UCase("dt")
    | StartText
    | End Select
    | End Sub
    |
    | Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
    | Select Case CommandName
    | Case UCase("mtext"), UCase("text"), UCase("mtedit"), UCase("dtext"),
    | UCase("ddedit"), UCase("ddatte"), UCase("et"), UCase("dt")
    | TextDone
    | End Select
    | End Sub
    |
    | Private Sub StartText()
    | GetKeyboardState kbArray
    | kbArray.kbByte(VK_CAPITAL) = 1
    | SetKeyboardState kbArray
    | End Sub
    | Private Sub TextDone()
    | GetKeyboardState kbArray
    | kbArray.kbByte(VK_CAPITAL) = 0
    | SetKeyboardState kbArray
    | End Sub
    |
    | it's supposed to set caps on at any command that requires 'typing' in the
    | acad editor and then turn it off so when I post here all my dumb questions
    | you guys don't yell at me for yelling at you!
    | :)
    |
    | some other condition must be affecting whether it works or not but I can't
    | figure out what that is.
    | Mark
    |
    |
     
    R. Robert Bell, Aug 7, 2003
    #2
  3. Mark Propst

    Jeff Mishler Guest

    Mark,
    I've been using this for about a month now and have observed this, too. I
    have noticed it seems to happen more often in the first drawing of the acad
    session, almost like it won't work until a certain command or action has
    occurred. However, it doesn't happen enough for me to remember to watch for
    when it does/doesn't work.....
    I know, not much help, just a confirmation.....will try to be more observant
    and attempt to track this down....
    And just for the record, I have the following comments in my dvb file:
    '''Functions by Bobby C. Jones of AcadX.com
    '''Subs by Mark Propst, posted to the autodesk VBA newsgroup
    '''June 23, 2003

    Jeff
     
    Jeff Mishler, Aug 8, 2003
    #3
  4. Mark Propst

    Mark Propst Guest

    _off_?

    Sometimes it works turning caps _on_
    if it turns them on, it always turns them off (even though the endcommand
    event doesn't fire if I cancel the command, the caps do *not* remain on as
    one would expect)
    well, now that's the interesting thing, cause I may be crazy...yeah I heard
    you, what do I mean *may be*....,
    but although I did discover that the command ended event did not fire when a
    command was cancelled, yet the caps did not remain on even after
    cancelling...!!!
    I can call mtedit, watch the command event fire, type in the mtext dialog,
    confirm caps are on, then cancel the commmand, notice that the endcommand
    event does *not* fire, but open notepad and type and caps are off!!!
    how weird is that? It's like canceling the mtedit command also canceled the
    starttext sub???
    And as jeff noticed this seems to definitely not work when I first open a
    drawing.
    if I start acad from a desktop shortcut, enter a text command(that is on the
    list), the starttext sub does not run, I can do that several times, creating
    or editing text and the events don't fire, but if I alt+f11 to bring the
    vbaide up, and alt+f11 to close it again, and then type, voila the events
    fire!!!
    I remember back when I was asking about this routine someone had a better
    one that also fired the light on the keyboard...I'll have to go back and try
    to find that one, maybe it's more reliable.
    ps win2k ac2k2

    and thanks to Jeff for reminding me who the author was.( I thought it was
    Bobby or Robert but they look so much alike you know???)
    :)
     
    Mark Propst, Aug 8, 2003
    #4
  5. Mark Propst

    Jeff Mishler Guest

    Hmmm,
    I should have read your original post a little better, Mark. I just figured
    you were using the newer code that turns the light on/off since that is the
    "final" code you posted back in the June thread "caps lock ala wonder
    llama"....this is the code I am using, with the same sporadic results...

    I have not, though, noticed where the caps will turn off as you
    describe.....

    Jeff
     
    Jeff Mishler, Aug 8, 2003
    #5
  6. Mark Propst

    Mark Propst Guest

    AND FURTHER....oops...and further curiousity...
    I replace the previous code with Bobby Jones' Class module technique and
    that does act as Robert said, leaving caps on after a cancel
    it also does not fire until the vbaide has been brought up at least once
    this appears on command line after alt+f11
    Command: _vbaide Initializing VBA System...
    Loading VBA startup file...
    thus it appears that acad.dvb does not actually load when acad starts as I
    had previously thought. I'll have to go back and reread the help files.
    apparently you have to run the ide once to get vba functionality?
    or probably run any vb command
    yep, just tried it, in a new dwg i run a vb command and get
    Command: -VBARUN Initializing VBA System...
    then the caps lock thingie is active.
    so I guess I 'm curious if theres' a trick to getting acad.dvb to actually
    run on startup, I guess create a dummy vb command that does nothing and call
    it from lisp in acaddoc.lsp would probably work.
    oh there it is in the help files
    You cannot load VBA until an AutoCAD VBA command is issued. If you want to
    load VBA automatically every time you start AutoCAD include the following
    line in the acad.rx file:

    acadvba.arx
    silly me
     
    Mark Propst, Aug 8, 2003
    #6
  7. Mark Propst

    wivory Guest

    Hmmm...note the CAVEAT EMPTOR on the above web page.
    &nbsp;&nbsp;
    ;-)
    &nbsp;&nbsp;
    Regards
    &nbsp;&nbsp;
    Wayne
     
    wivory, Aug 8, 2003
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.