TheSwamp

Code Red => VB(A) => Topic started by: Bryco on April 29, 2006, 04:29:16 PM

Title: Caps
Post by: Bryco on April 29, 2006, 04:29:16 PM
We always use caps in cad so it drives me nuts writing emails etc and finding caps on. I think I have a solution thanks to MP (http://www.theswamp.org/index.php?topic=9829.msg126287#msg126287) and dubb accidently yelling.
Even though this is virtually a straight copy it took an hour to figure out a way to make it shout when I wanted to. Api's are a bit tricky.
If there is a better way I'm all ears.

Code: [Select]
Option Explicit

Private WithEvents AutoCAD As AcadApplication


Private Declare Function FindWindow _
    Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long

Private Declare Function GetActiveWindow _
    Lib "user32" () As Long

Private Declare Sub keybd_event _
    Lib "user32" _
    (ByVal virtualKeyCode As Byte, _
    ByVal stubbed As Byte, _
    ByVal flags As Long, _
    ByVal pointerToExtraInfo As Long)

Private Declare Function MapVirtualKey _
    Lib "user32" _
    Alias "MapVirtualKeyA" _
    (ByVal virtualKeyCode As Long, _
    ByVal translate As Long) _
    As Long

Private Declare Function GetKeyState _
    Lib "user32" _
    (ByVal virtualKeyCode As Long) _
    As Long
   
Private Const _
    VKC_CAPSLOCK = &H14, _
    TRANSLATE_TO_SCANCODE = 0, _
    SCANF_KEYUP = &H2, _
    SCANF_KEYEXT = &H1, _
    SCANF_KEYNOTEXT = &H0, _
    NULL_POINTER = 0, _
    SCANF_KEYDOWN = &H28


Public Sub Acadstartup()
  Set AutoCAD = Application
  AutoCAD.WindowState = acMax
  ThisDrawing.WindowState = acMax
End Sub


Private Sub AutoCAD_AppActivate()
    Set AutoCAD = Application
    Dim Shout As Long
    Dim Key As Long
    Key = GetKeyState(VKC_CAPSLOCK)
    If GetActiveWindow = FindWindow("wndclass_desked_gsk", vbNullString) Then
        If Key = 1 Then
            Shout = SCANF_KEYEXT Or SCANF_KEYNOTEXT
        End If
    Else
        If Key = 0 Then
            Shout = SCANF_KEYDOWN
        End If
    End If
    If Shout Then ToggleShout (Shout)
End Sub

Private Sub AutoCAD_AppDeactivate()
    If GetKeyState(VKC_CAPSLOCK) = 1 Then
        ToggleShout (SCANF_KEYEXT)
    End If
End Sub



Sub ToggleShout(Shout As Long)
       
    Call keybd_event( _
        VKC_CAPSLOCK, _
        MapVirtualKey(VKC_CAPSLOCK, TRANSLATE_TO_SCANCODE), _
        Shout Or SCANF_KEYNOTEXT, _
        NULL_POINTER)
    Call keybd_event( _
        VKC_CAPSLOCK, _
        MapVirtualKey(VKC_CAPSLOCK, TRANSLATE_TO_SCANCODE), _
        Shout Or SCANF_KEYUP, _
        NULL_POINTER)
End Sub
Title: Re: Caps
Post by: Jeff_M on April 29, 2006, 06:05:38 PM
You might find THIS (http://www.theswamp.org/index.php?topic=4658.0) thread informational/useful
Title: Re: Caps
Post by: Bryco on April 30, 2006, 10:52:51 AM
Good article. Do you need VB to get the download to work?
Title: Re: Caps
Post by: Jeff_M on April 30, 2006, 02:31:12 PM
No, but there is a dll mentioned that you must have available.
Title: Re: Caps
Post by: Bryco on April 30, 2006, 05:48:12 PM
All the dll's are in C:\WINNT\system32  but some of them are named in caps if that makes a difference.
Title: Re: Caps
Post by: Keith™ on April 30, 2006, 10:00:09 PM
Caps make no difference .. so long as the files are located in the system folder and are pointed to in the registry ...