TheSwamp

Code Red => VB(A) => Topic started by: MP on April 05, 2005, 03:35:43 PM

Title: A person who shall remain nameless ...
Post by: MP on April 05, 2005, 03:35:43 PM
... in a forum similarly unnamed posted a response to another poster, all in annoying uppercase.

A lengthy paragraph of BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA BLA ...

I responded with this --

Code: [Select]
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
   
Sub StopShouting()
    If (GetKeyState(VKC_CAPSLOCK) And 1) Then
        Call keybd_event( _
            VKC_CAPSLOCK, _
            MapVirtualKey(VKC_CAPSLOCK, TRANSLATE_TO_SCANCODE), _
            SCANF_KEYEXT Or SCANF_KEYNOTEXT, _
            NULL_POINTER)
        Call keybd_event( _
            VKC_CAPSLOCK, _
            MapVirtualKey(VKC_CAPSLOCK, TRANSLATE_TO_SCANCODE), _
            SCANF_KEYEXT Or SCANF_KEYUP, _
            NULL_POINTER)
    End If
End Sub

Sub Main()
    Call StopShouting
End Sub

Person sends me an email, "NOT TO SOUND MORE STUPID THAN I ALREADY AM ... WHAT DID ALL THAT CODING STUFF MEAN?"

True story.

An aside, if you propeller heads are curious ... keybd_event (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/keybd_event.asp), MapVirtualKey (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/mapvirtualkey.asp) and GetKeyState (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/getkeystate.asp).
Title: A person who shall remain nameless ...
Post by: JohnK on April 05, 2005, 03:46:00 PM
Bawahahah! Thats funny!

Hey BTW, thats perdy cool, did you write that MP?
Title: A person who shall remain nameless ...
Post by: MP on April 05, 2005, 06:05:27 PM
I found (http://groups.google.ca/groups?hl=en&lr=&selm=224AAE92B1F4456FA9F7D827E13C0320%40in.WebX.maYIadrTaRb) a couple links (http://groups.google.ca/groups?hl=en&lr=&selm=E6DF28C54FED15C6B71EC02BC86543A5%40in.WebX.maYIadrTaRb) using google. Neither of them did exacty what I wanted and / or worked under XP, but it was enough that when I went to MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput.asp) I knew what I was looking for which enabled me to write what I wanted. Funny code (in the context that it was provided) but it does work.

I write my VB similar to my LISP, insomuch as the vertical style is concerned.

:)
Title: A person who shall remain nameless ...
Post by: Keith™ on April 05, 2005, 06:43:04 PM
Thanks for the code bit, that will be really helpful. I am thinking about putting it into a module that will take off caps lock when the browser has focus. That should prevent me from shouting at everyone ...
Title: A person who shall remain nameless ...
Post by: MP on April 05, 2005, 07:36:44 PM
Glad you can use it for something Keith. I wrote and posted it as a joke - when the lads at work found out it was actually functional they lost it. Admittedly, we're a weird bunch. :)
Title: A person who shall remain nameless ...
Post by: JohnK on April 05, 2005, 09:34:10 PM
That's when i found i the funniest. I teied it out and i almost wet my pants laughing!

Keith, make it so that anytime you launch TEXT, DTEXT it turns caps on.
Title: A person who shall remain nameless ...
Post by: Keith™ on April 05, 2005, 11:12:33 PM
I can do that ... Look for a neat little VBA app coming soon to a swamp near you..
Title: A person who shall remain nameless ...
Post by: Keith™ on April 08, 2005, 09:20:41 AM
Ok, boys and girls ... here (http://www.theswamp.org/lilly_pond/keith/CapsMan.exe?nossi=1) is the very first incarnation ... well if you count the code above, it is the second. I had to do alot of changes to the code so it would work properly in other Windows platforms, but credit for the original idea goes to MP.

The premise is that when a window becomes active it notifies the OS, we can intercept those calls with a simple timer, get the active window, determine what application it is from, and if it is AutoCAD, turn Caps Lock ON if it is a browser window, turn Caps Lock OFF. Well, that is how it is SUPPOSED to work.

I don't have FireFox installed here unfortunately so I am not able to verify it working properly with it. If anyone has a problem with it working properly send me a screenshot of the browser window or AutoCAD window and I will attempt to resolve the problem.

And give me some feedback ...

Enjoy .. I know that I am going to use it...
Title: A person who shall remain nameless ...
Post by: daron on April 08, 2005, 09:25:57 AM
It works just fine in Firefox and Autocad. That is sweet.
Title: A person who shall remain nameless ...
Post by: Keith™ on April 08, 2005, 09:41:30 AM
Did you see that it puts a little icon in the systray? To close the app, simply right click on the icon and select EXIT, otherwise it stays running in the background.
Total memory usage in my tests has been observed between 3 and 5 megs, while it is a little high for the size of the app, I think most of it can be attributed to the overhead needed to run in the systray.
Title: A person who shall remain nameless ...
Post by: Jeff_M on April 08, 2005, 09:51:46 AM
Well, it works fine going to FireFox, but does not work going to Autocad(Actually LandDesktop3 which is based on R2002)

How hard would it be to add options for email/newsgroup clients?
Title: A person who shall remain nameless ...
Post by: JohnK on April 08, 2005, 09:59:41 AM
*lol* Awesome! I love it!

What about this option. (Maybe this will be easier) In Acad; Toggle the caps on before the Text is typed and after the command is over, toggle it off.
Title: A person who shall remain nameless ...
Post by: Keith™ on April 08, 2005, 10:05:11 AM
It shouldn't be too difficult to add email and newsreaders. I was thinking of making it so that the user could add their own apps and state of CapsLock for those apps, but that was a whole lot more coding than I found myself wanting to do on a project that might amount to nothing.

I didn't have access to LDD or any of the other add-on packages offered by Autodesk, as a result I was not able to determine what criteria to use in order to properly manage it.

I'll see what I can do, in the meantime, if you can let me know which ones you want to add or simply send me a screenshot of each app you would like it to work with.
Title: A person who shall remain nameless ...
Post by: Jeff_M on April 08, 2005, 10:28:48 AM
Quote from: Keith

I'll see what I can do, in the meantime, if you can let me know which ones you want to add or simply send me a screenshot of each app you would like it to work with.

Thanks Keith.
Here's (http://www.theswamp.org/lilly_pond/jeff_m/Jeff_M_Apps4Caps.jpg?nossi=1) a pic of what I use other than Firefox.
Title: A person who shall remain nameless ...
Post by: daron on April 08, 2005, 10:50:18 AM
I think Se7en's idea would be ideal, since there are a few areas that would be useful to have them off, such as login after screensaver was activated.
Title: A person who shall remain nameless ...
Post by: David Hall on April 08, 2005, 10:57:22 AM
I DL and tried, and it appears to work when I start acad, in that it turns caplock on.  When I click/alttab toa browser, it turns it off.  BUT when I give acad focus, it does not turn it back on.  I checked both boxes in the setup. Was that right?

BTW, I have this code that does the same thing that Se7en is suggesting, in that my code turns on caps for text commands.
Code: [Select]
Option Explicit
Private WithEvents AutoCAD As AcadApplication
'Begin Code Block

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)
  If CommandName = "TEXT" Or CommandName = "EATTEDIT" Or CommandName = "DTEXT" Or CommandName = "INSERT" Or CommandName = "DDATTE" Or _
  CommandName = "DDEDIT" Then
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = 1
    SetKeyboardState kbArray
  End If
End Sub

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
  If CommandName = "TEXT" Or CommandName = "EATTEDIT" Or CommandName = "DTEXT" Or CommandName = "INSERT" Or CommandName = "DDATTE" Or _
  CommandName = "DDEDIT" Then
    GetKeyboardState kbArray
    kbArray.kbByte(VK_CAPITAL) = 0
    SetKeyboardState kbArray
  End If
End Sub
'End Code Block

I got this from CadVault , I think Randall Rath is the author

this goes inthe "This Drawing " module
Title: A person who shall remain nameless ...
Post by: MP on April 08, 2005, 10:57:53 AM
I can't try your utility out because our security won't allow downloads but I'm sure it's pretty derned cool, so kudos to you Keith.
Title: A person who shall remain nameless ...
Post by: David Hall on April 08, 2005, 11:02:26 AM
Can you get it by email?  I'll send it to you w/o the EXE extension if that would help
Title: A person who shall remain nameless ...
Post by: MP on April 08, 2005, 11:05:14 AM
That's a very kind offer CmdrDuh, but that will just set off a triple alarm (our scanner is not so easily fooled), so please don't.

:cheesy:
Title: A person who shall remain nameless ...
Post by: Keith™ on April 08, 2005, 11:21:57 AM
Updated -
Internet Explorer
FireFox
Netscape
Outlook
Outlook Express
AutoCAD products

Daron, I'll look into the possibility of having it interact with password boxes
Title: A person who shall remain nameless ...
Post by: daron on April 08, 2005, 12:47:45 PM
That'd be cool, thanks.
Title: A person who shall remain nameless ...
Post by: hudster on April 08, 2005, 02:50:46 PM
This is a sweet app Keith.

You are without doubt one of the finest individuals I know, in fact that goes for everyone on this site.  There isn't anyone here who is pretentious or too important to lend a bit of advice or support, and yes I'm even including Dent in that.  Even if he is a wee bit weird.

You are all amazing.
Title: A person who shall remain nameless ...
Post by: Jeff_M on April 08, 2005, 03:26:07 PM
Good job, Keith....albeit just one glitch I've found in the new version. Since, I assume, you are using the Title in the application bar to determine what status to use there is a conflict when using Outlook Express to access the autodesk.autocad.anything newsgroups......it appears that the "autocad" overrides the "outlook".

Thanks again, this should save a lot of us some embarassment or at least a ton of retyping..... :D
Title: A person who shall remain nameless ...
Post by: Keith™ on April 08, 2005, 03:47:30 PM
Well, I'll see what I can do about that ... That is why we have beta testers ... (ya didn't know you were one of them buggers did you)

*edited*

Updated .... it "should" work properly now ... If not, I'll try again ... It was basically an error in the parsing ... all should be well..
Title: A person who shall remain nameless ...
Post by: hudster on April 09, 2005, 07:43:48 AM
Keith, When I click the about button, I get a runtime error 713 message and then the app crashes.
Title: A person who shall remain nameless ...
Post by: Keith™ on April 09, 2005, 09:23:19 AM
Check to see if you have these files on your system.
FM20.dll
comctl32.dll
stdole2.tlb
msvbvm60.dll
Title: A person who shall remain nameless ...
Post by: Jeff_M on April 09, 2005, 03:18:37 PM
Key Keith, looks to me like you got it nailed now!
I like it!
Thanks again,
Jeff

Oh, and I couldn't duplicate Hudster's error......
Title: A person who shall remain nameless ...
Post by: hudster on April 10, 2005, 06:32:56 AM
I have them all except the fm20.dll file.
Title: A person who shall remain nameless ...
Post by: Keith™ on April 10, 2005, 10:30:25 AM
Ok, then that is your problem ... It can be downloaded from Microsoft from here (http://download.microsoft.com/download/office97pro/fm2past/97/WIN98/EN-US/fm2paste.exe)
Title: A person who shall remain nameless ...
Post by: whdjr on April 12, 2005, 10:46:53 AM
Keith I know this was all done in jest but it works really well.  I have mine set to autoload at windows startup.  Do you think you might be able to add in a quiet startup so the dialog box does not come up every time windows starts?

please!please!please!please!please!please!
Title: A person who shall remain nameless ...
Post by: Keith™ on April 12, 2005, 12:46:01 PM
Ok, you got what you wanted ...
To make it load quietly during windows startup, simply add /quiet to the shortcut properties i.e.

C:\MyProgs\CapsMan.exe /quiet

I was gonna do it anyway ... the new version is uploaded here (http://www.theswamp.org/lilly_pond/keith/CapsMan.exe?nossi=1) for your convenience.

Hudster, did you get the fm20.dll file downloaded and installed?

Enjoy ....
Title: A person who shall remain nameless ...
Post by: ronjonp on April 12, 2005, 01:59:48 PM
That's a sweet little program Keith :)
Title: A person who shall remain nameless ...
Post by: whdjr on April 12, 2005, 02:18:21 PM
Thanks Keith

That was too easy.

 :D
Title: A person who shall remain nameless ...
Post by: Keith™ on April 12, 2005, 02:35:46 PM
Maybe I'll make a little install proggie for it ... I have also been looking at giving the user the ability to add their own programs to the list. That will likely be a little bit down the road though.. I don't really have the time to devote to it right now...
Title: A person who shall remain nameless ...
Post by: jonesy on April 13, 2005, 08:13:12 AM
Your little proggy is great. Thanks very much!
Title: A person who shall remain nameless ...
Post by: MP on April 13, 2005, 08:25:57 AM
BTW ... I tried this little utility out (on Sunday I think) and have to say it's pretty nifty, good job Keith.

If you want to get ambitious you could have it (as an option on the settings dialog of course) install a shortcut in the startup folder.

Also, you could have it "learn", by pointing to a running instance of a program: "Yes, that window right there <click>. When it gets focus force caps lock on/off".

When you're not doing anything else of course.

:)
Title: A person who shall remain nameless ...
Post by: JohnK on April 13, 2005, 08:46:21 AM
Hey, Pop it into the CVS and maybe a bunch of us can help out with diff ideas and stuff. (Just an idea)
Title: A person who shall remain nameless ...
Post by: Keith™ on April 13, 2005, 03:04:24 PM
I'll see what I have and may just do that ...
Title: A person who shall remain nameless ...
Post by: David Hall on May 09, 2005, 12:53:35 PM
Any chance of getting it to turn off Caps when I go into MS Word?
Title: A person who shall remain nameless ...
Post by: Keith™ on May 09, 2005, 01:08:07 PM
It is a possibility ~ this project has been on hold for now until I can find the time to get it uploaded and/or completed. It has come to the point where I think the user should be allowed to add the programs on the fly.
Title: Re: A person who shall remain nameless ...
Post by: Slim© on April 30, 2006, 10:57:41 AM
Hey Keith,

Any idea when you might update this proggy? I like it alot. :-)
Thanks.
Title: Re: A person who shall remain nameless ...
Post by: Maverick® on April 30, 2006, 12:00:02 PM
  I finally saw this.  I will have to see if this works with Softplan instead of Acad.  I'm thinking I will probably have to wait until Keith gets it to where the user can add programs and specify caps or no.  This would be SO nice to have. 
Title: Re: A person who shall remain nameless ...
Post by: Keith™ on April 30, 2006, 09:59:10 PM
Well, I had all but forgotten about this .. I still don't have a whole lot of time to devote to it .. Let me dig up the code and look at it .. I'll have to figure out where I left off ... it has been almost a ...correction it HAS been a year since I have messed with it ....
Title: Re: A person who shall remain nameless ...
Post by: Slim© on May 01, 2006, 12:43:59 AM
Thanks for checkin' up on it Keith, no big rush, just when you get time. :wink:
Title: Re: A person who shall remain nameless ...
Post by: Krushert on December 04, 2006, 09:32:13 AM
Quote
   
The following error or errors occurred while posting this message:
Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

I know this was yelling at me but I had to reply in hopes to draw attention so that another Johnny-Come-Lately like myself could use this absolutely sweet loving extraordinary deliciously fabulous gift that could only come from the Gods.


Thanks Keith, MP and all the Beta testers  Thank you very much!!
Title: Re: A person who shall remain nameless ...
Post by: CADaver on December 04, 2006, 01:22:39 PM
Don't know How I missed this the first times around, thanks for the bump.
Title: Re: A person who shall remain nameless ...
Post by: Slim© on December 04, 2006, 02:42:30 PM
I know this was yelling at me but I had to reply in hopes to draw attention so that another Johnny-Come-Lately like myself could use this absolutely sweet loving extraordinary deliciously fabulous gift that could only come from the Gods.

Thanks Keith, MP and all the Beta testers  Thank you very much!!

I've been thinkin' about bumpin' this one to the top lately meself. THX Krushert.

Any time you can Keith...