TheSwamp

Code Red => .NET => Topic started by: Chuck Gabriel on June 14, 2006, 08:24:54 PM

Title: Managed HotKeys
Post by: Chuck Gabriel on June 14, 2006, 08:24:54 PM
For those of you who care, I've been working on a C# version of HotKeys to address the requests I've been getting for an AutoCAD 2007 compatible version of the app.  I built it using Visual C# 2005 Express, version 2.0 of the .NET framework, and the ObjectARX 2007 API.

This is my first attempt at writing a managed app for AutoCAD, and I don't have a .NET enabled version of AutoCAD to test it with, so it might not work quite right just yet.  Hopefully it can be knocked into shape with a little user feedback.

For current HotKeys users, copy HotKeys.dll into your current HotKeys application folder and netload it.  The program should set up necessary registry keys, load your keys file, and turn on the hooks upon loading.

The app defines the following commands:

KeysOn -> Turns on the hooks
KeysOff -> Turns off the hooks
KeysToggle -> Toggles the on/off status of the hooks
KeysConfig -> Displays the configuration dialog
EditKeys -> Runs the keys file editor (should force a reload of the keys file upon closing)

The editor isn't in the zip file, so expect the editkeys command to flop if you don't already have an older version of HotKeys installed.

[added.kdub]
Revised 2010.11.17
Hotkeys[2010]
http://www.theswamp.org/index.php?topic=10570.msg409779#msg409779
Title: Re: Managed HotKeys
Post by: Kerry on June 14, 2006, 08:43:29 PM
Ohhhh shiney !!

I'll have a look tonight Chuck .. THANKS !!
Title: Re: Managed HotKeys
Post by: Glenn R on June 14, 2006, 09:46:14 PM
Chuck, of course we care...where-ever did you get the idea we didn't? :)
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 14, 2006, 10:45:46 PM
Thanks Glenn.  I was thinking more of the people who might read this thread and think "What the heck is a HotKeys?"
Title: Re: Managed HotKeys
Post by: FengK on June 15, 2006, 01:47:09 AM
Thanks a lot Chuck.  I'll be glad to test it out.  I've been using HotKeys for couple of months and really liked it.
Title: Re: Managed HotKeys
Post by: hudster on June 15, 2006, 03:21:09 AM
Oh I've been waiting for this to be updated for ages.

I love your hotkeys program, I've setup so many shortcuts with it, when it didn't work with 2007 I was lost, i still type in the shortcuts I used with hotkeys now.

Hooray Chuck your a gent mate. :-D
Title: Re: Managed HotKeys
Post by: hudster on June 15, 2006, 03:48:08 AM
Ok I get this when I try keysconfig

Code: [Select]
Application does not support just-in-time (JIT)
debugging. See the end of this message for details.

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'HotKeys.Main' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at HotKeys.AppRegistry.get_allowCapsLockMod()
   at HotKeys.Main..ctor()
   at HotKeys.Main..cctor()
   --- End of inner exception stack trace ---
   at HotKeys.Main.keysOn()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction)
   at AcMgCommandClass.Invoke(AcMgCommandClass* , gcroot<System::Reflection::MethodInfo ^>* mi, Boolean bLispFunction)
   at Autodesk.AutoCAD.Runtime.TargetInvocationSEHExceptionFilter.InvokeWorker()
   at Autodesk.AutoCAD.Runtime.ExceptionFilter.Invoke()


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
acdbmgd
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/AcdbMgd.DLL
----------------------------------------
msvcm80
    Assembly Version: 8.0.50608.0
    Win32 Version: 8.00.50727.42
    CodeBase: file:///C:/WINDOWS/WinSxS/x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd/msvcm80.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
acmgd
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/acmgd.DLL
----------------------------------------
AcDxUi
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/AcDxUi.DLL
----------------------------------------
AcDx
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/AcDx.DLL
----------------------------------------
AcDxUi.resources
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/en-US/AcDxUi.resources.DLL
----------------------------------------
AcMgdShared
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/AcMgdShared.DLL
----------------------------------------
AcLayer
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/AcLayer.DLL
----------------------------------------
AcLayer.resources
    Assembly Version: 17.0.54.0
    Win32 Version: 17.0.54.0
    CodeBase: file:///C:/Program%20Files/AutoCAD%202007/en-US/AcLayer.resources.DLL
----------------------------------------
HotKeys
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Program%20Files/HotKeys2004/HotKeys.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------

************** JIT Debugging **************
Application does not support Windows Forms just-in-time (JIT)
debugging. Contact the application author for more
information.


Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 15, 2006, 07:32:44 AM
Thanks Andy.  That's just the sort of feedback I'm looking for.

I'll look into that and post back here once I know more, though I may have to rely on the kindness of other members, who are more experienced with .NET, to help me debug it.
Title: Re: Managed HotKeys
Post by: hudster on June 15, 2006, 08:56:57 AM
what ever it takes to get this excellent piece of software working with 2007, I'm there to help if I can.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 15, 2006, 12:32:36 PM
Ok.  I did some investigation and discovered that the problem Andy encountered had two causes.

1) I was trying to read a non-existent value from the registry.

2) I had a fundamental misunderstanding of how static objects are handled in .NET.  They aren't initialized until they are used (unlike C++).

Here is my next attempt.
Title: Re: Managed HotKeys
Post by: MickD on June 15, 2006, 06:43:53 PM
Hi Chuck, if you want to have a class that's guaranteed to be created on loading you can use the IExtensionApplication interface, this is an example I use for a current app -
Code: [Select]
namespace DCS_3D


{
///
/// The entry point for Autocad, it get's called at least once
/// when you use 'Netload' to load and configure your application
/// There can only be one instance of inherited IExtensionApplication
/// per class library.
///
public class App : IExtensionApplication
{
public static string appPath;
public void
Initialize()
{
appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
//Let the user know what's happening while loading your app
//You could also alert user of failed loading operations here.

//load the hlr api:
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.LoadModule("AsdkHlrApi16.dbx",true,true);

Utils.PrintMessage("\n Loading DCS_3D application...\n");
Utils.PrintMessage("\n Beta Version 0.1.6 2nd.June.2006.");
Utils.PrintMessage("\nEnter DCS3D to open DCS3D tools dialog:\n");

}

public void
Terminate()
{
//Nothing to put here yet!

}
}
}

I use this in all of my .net arx dll's to initialise application static ('global' like) variables or to load other classes or dialogs etc.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 15, 2006, 07:39:39 PM
Thanks Mick.  That's actually exactly what I did to resolve the issue I was having.
Title: Re: Managed HotKeys
Post by: hudster on June 16, 2006, 03:51:45 AM
Ok all the native hotkey commands, keysconfig etc, work fine.

Can't load the Arx file via startup suite though.

Also when i try to use any hotkeys, I get a fatal error. Autocad error details
Code: [Select]

UnloadedApps:AcLaunchNFWWS.arx(621a0000,b000);C:\Program Files\AutoCAD 2007\AcStar.arx(60170000,14000);
Clr Data:
   at HotKeys.HookProcedures.keyboardProc(Int32 code, IntPtr wParam, IntPtr lParam) in C:\Documents and Settings\Chuck2000\My Documents\Visual Studio 2005\Projects\HotKeys\HotKeys\HookProcedures.cs:line 165


  ]]>
  </AppCDATA>
  <OpenGLInfo Vendor="ATI Technologies Inc." Renderer="RADEON 7500 DDR x86/SSE2" Version="1.3.4454 WinXP Release" />
  </CERInfo>
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 16, 2006, 07:11:12 AM
Well I sure didn't see that coming.  I'll take another look and see what I can see.

Incidentally, you should not have to resort to the startup suite.  If you check "Load HotKeys at AutoCAD startup," then close and reopen AutoCAD, does it not load the DLL automatically?
Title: Re: Managed HotKeys
Post by: hudster on June 16, 2006, 07:21:42 AM
Nope, it only gives the option to load the arx file at startup, but this isn't compatible.

I need to reload the dll using netload each time.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 16, 2006, 07:40:37 AM
This appears to be where the error is occurring:
Code: [Select]
CmdActive cmdActive = (CmdActive)Application.GetSystemVariable("CMDACTIVE");

CmdActive is defined thusly:

Code: [Select]
        private enum CmdActive : int
        {
            CMDACTIVE_NONE = 0x0000,
            CMDACTIVE_ORDINARY = 0x0001,
            CMDACTIVE_ORDINARY_TRANSPARENT = 0x0002,
            CMDACTIVE_SCRIPT = 0x0004,
            CMDACTIVE_DIALOG = 0x0008,
            CMDACTIVE_AUTOLISP = 0x0010
        }

My first thought would be to store the return value from GetSystemVariable in an int rather than trying to cast it directly to one of the enum values.  Can anyone verify that?  I don't want to waste Andy's (or anyone else's time) blindly testing iteration after iteration of the code.

Regarding the demand loading Andy, you should have a key in your registry similar to this:

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R15.0\ACAD-1:409\Applications\HotKeys.NET

If you do, could you export that key to a file and post it here?  If you don't have a key like that then the bug is more fundamental than I'm thinking.

BTW - What do you mean by "this isn't compatible?"
Title: Re: Managed HotKeys
Post by: hudster on June 16, 2006, 08:49:57 AM
i've sent you a pm with the file attached.**edit** coulodn't get logged in to my lily pond account so i'll attach the zip here

by not compatible, I mean Autodesk re-wrote the arx components stuff for 2007, so some of the old arx stuff doesn't load anymore

I get this message when I try to load hotkeys.arx - C:\Program Files\AutoCAD 2007\acad.exeUnable to load AsdkHotKeys.arx file.

Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 16, 2006, 09:43:03 AM
When i said this:

Incidentally, you should have to resort to the startup suite

I actually meant this:

Incidentally, you should not have to resort to the startup suite

Sorry.  Hope that didn't cause too much confusion.

Still, after looking at the info from your registry, I'm at a loss as to why demand loading isn't working.  Everything looks just like I think it should in the file you attached.

As to the other issue, if I don't hear from any of the other members about it, I'll go with my gut and post the updated code this evening (my time).
Title: Re: Managed HotKeys
Post by: hudster on June 16, 2006, 09:53:17 AM
If I don't use netload and load the dll, none of the hotkey commands work, not even the keysconfig.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 16, 2006, 08:36:13 PM
Here is a stab in the dark.

I'm still clueless about the demand loading issue.  Perhaps someone else will chime in with something that will break the case.
Title: Re: Managed HotKeys
Post by: Kerry on June 16, 2006, 08:42:44 PM
Demand loading can be managed with a registry entry ..

I'm running at the moment .. will try to elucidate when I have time ..
... Have a look at the Layers managed interface demand load entry ..

added:
This may help

http://images.autodesk.com/adsk/files/AutoCAD_2006_API_Overview.ppt   <<<< about half way through the doc

more added:
Quote
[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Applications\AcLayer]
 "DESCRIPTION"="AutoCAD Layer Manager"
 "LOADER"="C:\\Program Files\\AutoCAD 2006\\aclayer.dll"
 "LOADCTRLS"=dword:0000000e
 "MANAGED"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Applications\AcLayer\Commands]
 "LAYER"="LAYER"

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Applications\AcLayer\Groups]
 "ACLAYER_CMDS"="ACLAYER_CMDS"

HKEY_LOCAL_MACHINE
    SOFTWARE
        Autodesk
            AutoCAD
                R16.2 <<<<  [ or whatever ]
                    [Your AutoCAD Version Key]
                        Applications
                            [Your app name]

Create the following values under the key:

DESCRIPTION = [A description of your app]
LOADER = [Full path to your assembly DLL]
MANAGED = 1 (dword)
LOADCTRLS = 2 (dword)

Look in the ObjectARX documentation for the values you can use for LOADCTRLS. The value 2 is used when you want your app to load when AutoCAD starts up.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 16, 2006, 09:34:43 PM
Thanks Kerry.  MANAGED is not documented.  I assume that's what has been tripping me up.
Title: Re: Managed HotKeys
Post by: LE on June 16, 2006, 09:44:59 PM
Do not know if for managed code the sample provided in the ARX SDK of polysamp could help.

Have a look into: samples\entity\polysamp\demandload directory
Title: Re: Managed HotKeys
Post by: Glenn R on June 16, 2006, 09:46:30 PM
Also Chuck, I think you will want to cast to a short instead of int...I've noticed this with sysvars that return int.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 16, 2006, 09:52:14 PM
Luis - I was missing the dword value named MANAGED, which apparently is required for managed apps but not for unmanaged, and is completely undocumented.

Glenn - Thanks for the tip.  I'll probably incorporate that into the next round of changes (I feel sure there will be one).
Title: Re: Managed HotKeys
Post by: Bobby C. Jones on June 17, 2006, 11:53:38 PM
Thanks Glenn.  I was thinking more of the people who might read this thread and think "What the heck is a HotKeys?"
What the heck is a HotKey, Chuck?

Modified: Added a comma after HotKey per my 14 y.o. daughter  :-D
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 18, 2006, 10:27:59 AM
Thanks Glenn.  I was thinking more of the people who might read this thread and think "What the heck is a HotKeys?"
What the heck is a HotKey Chuck?

AsdkHotKeys.arx is (and HotKeys.dll hopefully eventually will be) an ObjectARX application that allows users to assign actions to keystroke combinations in AutoCAD.  The main thing that sets it apart from standard AutoCAD keyboard accelerators is that it allows you to use the ALT key in your key combinations.  It has a couple of other unusual features that were actually requested by users (otherwise I would never have believed anyone would have wanted those features).

I wrote it for my own use, but then decided to give it away as a way of saying thanks to all the people in forums like this that had helped me learn what I needed to know to write it.

The original application was written in C++, which made it impractical for me to update it for new versions of AutoCAD, since I have not upgraded since 2000i.  Fortunately, when Autodesk forced developers to upgrade to Visual Studio 2002 Glenn R. generously offered to update the program for AutoCAD 2004.  That version continued to be usable through AutoCAD 2006 (or so I am told), but then Autodesk decided that it was again time to force developers to upgrade to Microsoft's latest development environment.  The managed API (and the free tools available to code for it) presented an opportunity for me to try to update the program myself without having to purchase any expensive development tools.  Unfortunately, I still can't test the application myself (AutoCAD 2000i).

Aren't you glad you asked? :D
Title: Re: Managed HotKeys
Post by: hudster on June 19, 2006, 03:53:26 AM
still crashing whenever I try to use any hotkey I've setup.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 19, 2006, 07:01:39 AM
Ok.  Let's try casting to a short per Glenn's suggestion then.

Title: Re: Managed HotKeys
Post by: hudster on June 19, 2006, 07:30:25 AM
Hooray it's working.

Cheers Chuck, you've made my day. :-)

***Edit ***

It now autoloads as well
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 19, 2006, 08:15:25 AM
Woo Hoo!

Thanks Andy, Glenn, Kerry, Luis, and Mick for all your help and suggestions.

Mark - would it be alright if I direct folks who inquire about HotKeys to TheSwamp, or would you prefer that I host it from my own space?
Title: Re: Managed HotKeys
Post by: Kerry on June 23, 2006, 12:09:41 AM
I feel really badly  :oops:   ... I downloaded the first version and STILL haven't made time to follow up.

Thanks Chuck, you're a real gent' !

Title: Re: Managed HotKeys
Post by: nivuahc on June 23, 2006, 07:05:05 AM
Woo Hoo!

Thanks Andy, Glenn, Kerry, Luis, and Mick for all your help and suggestions.

Mark - would it be alright if I direct folks who inquire about HotKeys to TheSwamp, or would you prefer that I host it from my own space?


Chuck, if you need someplace to host it, I can do that for you if Mark prefer it not be here. If you're talking about pointing people to TheSwamp and this thread, I can't imagine that Mark would have a problem with that, though I cannot speak for him directly. A PM might be in order just to clarify things.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 23, 2006, 11:15:21 AM
Kerry - No need to apologize.  You might want to get the last version posted though.  I can guarantee that the first version won't work at all.

Chuck (the other Chuck) - PM sent (for the record).
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on December 28, 2006, 02:45:41 PM
Kelie found a bug in the last version of HotKeys that I posted in this thread.  Basically, key combinations that already have some action assigned to them by vanilla AutoCAD would do those actions in addition to whatever commands you assigned to them using HotKeys.  I *think* the attached file will fix the bug.  Please let me know if I am wrong.
Title: Re: Managed HotKeys
Post by: FengK on December 28, 2006, 03:21:24 PM
Problem fixed. Thanks a lot Chuck.
Title: Re: Managed HotKeys
Post by: FengK on January 04, 2007, 12:50:58 PM
Does anyone using Hotkeys (either the .arx or .dll version) also have  this issue:

The Hotkeys are not disabled when there is a dialog (for example Text Edit or Attribute Edit dialog)?

Thanks.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on January 04, 2007, 01:28:37 PM
For those of you playing along at home, the following bit of code (located in HookProcedures.cs) is supposed to prevent the behavior Kelie is experiencing:

Code: [Select]
// Check to see if a modal dialog box is active
// If so, ignore hotkeys
CmdActive cmdActive = (CmdActive)((short)Application.GetSystemVariable("CMDACTIVE"));
if ((cmdActive & CmdActive.CMDACTIVE_DIALOG) == CmdActive.CMDACTIVE_DIALOG)
    return WindowsHook.CallNextHookEx(hHook, code, wParam, lParam);

Latest source code http://home.carolina.rr.com/hotkeys/ManagedHotKeys.zip.

Edit:  Tried to fix the url formatting, but no dice, so I changed it to a raw url.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on January 23, 2007, 09:44:06 PM
Problem solved.  The solution feels kind of kludgy to me (comparing thr first seven letters of the foreground window's caption to the word "AutoCAD"), but it works.

Latest version (binary and source) (http://home.carolina.rr.com/hotkeys/ManagedHotKeys.zip)
Title: Re: Managed HotKeys
Post by: Kerry on January 23, 2007, 10:22:01 PM
Thanks Chuck,

Very timely,
Mark and the boys [17 seats] are swinging over to AC2007 next week.

best regards
Kerry
Title: Re: Managed HotKeys
Post by: FengK on January 25, 2007, 11:30:13 AM
Chuck,

Thanks a lot for fixing the problem.  One other issue I'm experiencing is with HotKeyEdit.  With only .NET version installed, when trying to Save the .xml file after making changes, an error message pops up:
Run-time error '35006': The name is not in use for a subkey or named value. Any suggestion how to get around it?  For now, I'm using XML Notepad 2007 to edit the .xml file directly. 

Kerry, did you run into the same problem before?  Thanks.

--
Kelie
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on January 25, 2007, 01:06:46 PM
I am aware of that bug and I know the cause, but I just haven't been able to get motivated to fix it.  The problem is that the editor is trying to modify the registry key that HotKeys uses to store the location of the keys file, but it is looking in the wrong location in the registry.  It seems trivial on the surface, but once you dig a little deeper, you start to see that it will actually take significant time and effort to fix.  I just don't know when or if I will get to it, since it isn't a complete show stopper.

I mis-spoke, the problem is actually that the program is looking in the registry to figure out which folder it is installed in, but it is looking in the wrong section of the registry.  I'm looking into a way of fixing it that I hadn't previously considered.  Stay tuned.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on January 25, 2007, 01:51:10 PM
Looks like it wasn't as big of a deal as I thought.  I was just approaching the problem from the wrong angle.
Title: Re: Managed HotKeys
Post by: Kerry on January 25, 2007, 04:57:00 PM
......  Any suggestion how to get around it?  For now, I'm using XML Notepad 2007 to edit the .xml file directly. 

Kerry, did you run into the same problem before?  Thanks.

--
Kelie


Hi Kelie
I've/we've used the same XML for a while.  Haven't had an issue though.

Chuck, I recall there had been an issue with Reg keys that we manually edited.
I only have HK for 2006 installed on this box,so can't check ...
Title: Re: Managed HotKeys
Post by: Glenn R on January 25, 2007, 06:13:21 PM
Chuck, I use something like this to find out where I'm running from:
Code: [Select]
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string cfgPath = Path.Combine(path, "yourXmlFileNameHere.xml");
...
XmlDocument cfgDoc = new XmlDocument();
cfgDoc.Load(cfgPath);
//Rest of mojo here...

Cheers,
Glenn.

Title: Re: Managed HotKeys
Post by: Chuck Gabriel on January 25, 2007, 07:02:59 PM
Thanks guys.

Since HotKeysEdit is a VB6 app, I used GetModuleFileName to figure out where I was running from.  I actually tried to use Command$, but apparently that is only valid inside sub main.

I am aware of one other minor registry-related issue, but since nobody has ever mentioned it as a bug, I'm pretending it doesn't exist.

On a somewhat unrelated issue that may interest Glenn and Kerry, and perhaps a few others, acedGetVar and its managed equivalent both return a value of 1 for the CMDACTIVE system variable regardless of whether a modal dialog is active.  Don't you just love when the implementation disagrees with the documentation? :-p
Title: Re: Managed HotKeys
Post by: FengK on January 26, 2007, 05:54:13 PM
Just tried the revised HotkeyEdit and it works fine.  Thanks Chuck.  One question, after saving the modified the .xml file, does user have to restart AutoCAD for the new hotkey definition to work? I remember (not 100% sure) when using the .arx version, it wasn't necessary.

Thanks.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on January 26, 2007, 08:28:54 PM
You definitely don't have to restart AutoCAD.  You're not even supposed to have to reload your key definitions, but I don't know whether that feature is actually working.  At most, you should have to press Ctrl-K twice (or type the TOGGLEKEYS command twice, or type the KEYSOFF command followed by the KEYSON command).
Title: Re: Managed HotKeys
Post by: FengK on January 29, 2007, 05:29:19 PM
Chuck, KEYSOFF followed by KEYSON works.  Thanks again.
Title: Re: Managed HotKeys
Post by: Glenn R on January 29, 2007, 06:34:55 PM
Wax on, wax off...:D
Title: Re: Managed HotKeys
Post by: FengK on January 31, 2007, 03:17:41 PM
Just noticed a problem.  When editing MText (command MTEDIT), AutoCAD crashes if a hotkey combination is pressed.  Error messge is:
FATAL ERROR: Unhandled e0434f4dh Exception at 7c812a5bh.  Not sure if others have the same problem.  It does not happen when editing Text or Block attributes.  Thanks.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on February 07, 2007, 10:18:21 AM
Has anyone else experienced the bug Kelie described above?

Kelie - Do you have the setting that allows the CapsLock status to influence key combos turned on?
Title: Re: Managed HotKeys
Post by: FengK on February 07, 2007, 11:33:19 AM
Chuck, that option is not turned on. Thanks.
Title: Re: Managed HotKeys
Post by: FengK on October 30, 2007, 01:12:46 PM
I tried to set up Hotkeys on a new computer (from Dell). When using HotKeysEdit.exe, I got an error. Please see attched image. I'm guessing one of the old .ocx or .dll is missing or not registered properly on the new computer? Anyone has a clue?

Thanks!

(btw, just noticed .bmp file is not allowed as attachment here.)
Title: Re: Managed HotKeys
Post by: MP on October 30, 2007, 01:18:54 PM
(btw, just noticed .bmp file is not allowed as attachment here.)

Can you convert to png (preferred) or jpg? Bmps are notoriously bloated compared to the alternatives (like in a 10:1 magnitude). Thanks!

Edit: I see you figure it out; nevermind.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on October 30, 2007, 01:36:00 PM
I never got around to creating an installer for the managed version, but I'll take a look at the installer script for the unmanaged version when I get home and let you know what files need to be registered.
Title: Re: Managed HotKeys
Post by: FengK on October 30, 2007, 01:44:11 PM
Thanks a lot Chuck.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on October 30, 2007, 07:15:08 PM
Here is the list of files the installer registers:

COMCAT.DLL
comdlg32.ocx
HotKeyControl.ocx
OLEAUT32.DLL
OLEPRO32.DLL
MSCOMCTL.OCX
MSFLXGRD.OCX
msxml4.dll
regobj.dll
STDOLE2.TLB
Title: Re: Managed HotKeys
Post by: FengK on October 30, 2007, 08:47:16 PM
Chuck,

I copied all these files to system32 directory (most of them are already there), registered all them except for STDOLE2.TLB. (can't do it). Getting the same error when using HotKeysEdit.

Another problem I'm having is after NETLOAD the Hotkeys.dll, I'm getting "unknown command" response when using the KEYSCONFIG command. It seems the dll file was not actually loaded. This should have nothing to do with other .dll, .ocx or .tlb, right?

Thanks.
Title: Re: Managed HotKeys
Post by: FengK on October 30, 2007, 09:00:59 PM
I tried to set up Hotkeys on a new computer (from Dell). When using HotKeysEdit.exe, I got an error. Please see attched image. I'm guessing one of the old .ocx or .dll is missing or not registered properly on the new computer? Anyone has a clue?

Thanks!

(btw, just noticed .bmp file is not allowed as attachment here.)

i was able to fix this problem by installing the arx version (using the setup file HotKeys2004Setup_4.0.0.3.exe). since the arx version doesn't work with AutoCAD 2007, i uninstalled it right away. but the problem with HotKeyEdit was fixed.
Title: Re: Managed HotKeys
Post by: LE on October 30, 2007, 10:46:21 PM
), registered all them except for STDOLE2.TLB. (can't do it).

Kelie;

There is a tool here:

http://www.vbcodemagician.dk/resources/ccrpregutil.htm

By Brad Martinez

And can be use to install TLB's too [ocx - dll] (I been using it for so many years)
Title: Re: Managed HotKeys
Post by: FengK on October 31, 2007, 02:51:04 AM
Kelie;

There is a tool here:

http://www.vbcodemagician.dk/resources/ccrpregutil.htm

Thanks LE. Will try it tomorrow.
Title: Re: Managed HotKeys
Post by: FengK on November 08, 2007, 04:43:00 PM
Is anyone using Hotkeys with Civil3D? I tried compiling the project using acdbmgd.dll and acmgd.dll from C:\Program Files\Autodesk Civil 3D 2007. It reported 9 warnings, but no errors. After NETLOADing the dll, AutoCAD Civil3D 2007 crashes as soon as any hotkey combination is pressed. Any comments? Thanks!
Title: Re: Managed HotKeys
Post by: paulmcz on November 08, 2007, 05:37:18 PM
Is anyone using Hotkeys with Civil3D? I tried compiling the project using acdbmgd.dll and acmgd.dll from C:\Program Files\Autodesk Civil 3D 2007. It reported 9 warnings, but no errors. After NETLOADing the dll, AutoCAD Civil3D 2007 crashes as soon as any hotkey combination is pressed. Any comments? Thanks!

I had problems with making HotKeys work in Vanilla 2007. I tried many things but only when I added HotKeys folder in Program Files in the AutoCAD's search path, it solved the problem. I don't know if this will work in Civil3D but it could be worth to try it.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on November 08, 2007, 06:47:32 PM
Is anyone using Hotkeys with Civil3D? I tried compiling the project using acdbmgd.dll and acmgd.dll from C:\Program Files\Autodesk Civil 3D 2007. It reported 9 warnings, but no errors. After NETLOADing the dll, AutoCAD Civil3D 2007 crashes as soon as any hotkey combination is pressed. Any comments? Thanks!

Sorry Kelie.  I know absolutley nothing about Civil3D.
Title: Re: Managed HotKeys
Post by: FengK on November 09, 2007, 02:26:21 AM
I had problems with making HotKeys work in Vanilla 2007. I tried many things but only when I added HotKeys folder in Program Files in the AutoCAD's search path, it solved the problem. I don't know if this will work in Civil3D but it could be worth to try it.

thanks for your reply. i tried what you suggested and it didn't fix the problem.
Title: Re: Managed HotKeys
Post by: FengK on November 09, 2007, 02:29:31 AM
Sorry Kelie.  I know absolutley nothing about Civil3D.

That's quite alright, Chuck. I rarely use Civil3D myself. Since I have it installed, I wanted to see if Hotkeys can be used in it.
Title: Re: Managed HotKeys
Post by: Kerry on January 22, 2008, 10:22:56 PM
I tried to set up Hotkeys on a new computer (from Dell). When using HotKeysEdit.exe, I got an error. Please see attched image. I'm guessing one of the old .ocx or .dll is missing or not registered properly on the new computer? Anyone has a clue?

Thanks!

(btw, just noticed .bmp file is not allowed as attachment here.)

i was able to fix this problem by installing the arx version (using the setup file HotKeys2004Setup_4.0.0.3.exe). since the arx version doesn't work with AutoCAD 2007, i uninstalled it right away. but the problem with HotKeyEdit was fixed.

On a new installation, I'm having the same issue with the Editor ..
Can some kind soul please post the HotKeys2004Setup_4.0.0.3.exe so I can try Kelie's solution.
Title: Re: Managed HotKeys
Post by: paulmcz on January 22, 2008, 11:15:27 PM
Here you go
Title: Re: Managed HotKeys
Post by: Kerry on January 23, 2008, 03:43:46 AM
Thanks Paul  .. much appreciated .. the .EXE worked a treat
Title: Re: Managed HotKeys
Post by: FengK on March 04, 2008, 12:46:26 PM
Just noticed a problem.  When editing MText (command MTEDIT), AutoCAD crashes if a hotkey combination is pressed.  Error messge is:
FATAL ERROR: Unhandled e0434f4dh Exception at 7c812a5bh.  Not sure if others have the same problem.  It does not happen when editing Text or Block attributes.  Thanks.

An update for this problem. This behavior only occurs when system variable MTEXTED is set to OLDEDITOR. (In most cases, I don't like the new MTEXT editor).
Title: Re: Managed HotKeys
Post by: FengK on June 19, 2008, 07:35:47 PM
Kelie found a bug in the last version of HotKeys that I posted in this thread.  Basically, key combinations that already have some action assigned to them by vanilla AutoCAD would do those actions in addition to whatever commands you assigned to them using HotKeys.  I *think* the attached file will fix the bug.  Please let me know if I am wrong.

Chuck,

Can you tell me which part of the code is relevant to this problem? I looked through your code and could not spot it. The reason why I asked is because I would really like to get a working version of Hotkeys for Civil3D, but my C# knowledge is VERY limited. So I'm thinking of using a totally different approach: I'll use Python to monitor the key press event system wide, when a predefined key combination occurs, the corresponding commands will be sent to AutoCAD if the AutoCAD Application is active. It doesn't seem to be a difficult task, but I don't know how to turn off the default action associated with a particular key combination, such as "Alt+F" to pop up the "File" menu.

Thanks!


Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 20, 2008, 07:08:19 AM
Kelie found a bug in the last version of HotKeys that I posted in this thread.  Basically, key combinations that already have some action assigned to them by vanilla AutoCAD would do those actions in addition to whatever commands you assigned to them using HotKeys.  I *think* the attached file will fix the bug.  Please let me know if I am wrong.

Chuck,

Can you tell me which part of the code is relevant to this problem? I looked through your code and could not spot it. The reason why I asked is because I would really like to get a working version of Hotkeys for Civil3D, but my C# knowledge is VERY limited. So I'm thinking of using a totally different approach: I'll use Python to monitor the key press event system wide, when a predefined key combination occurs, the corresponding commands will be sent to AutoCAD if the AutoCAD Application is active. It doesn't seem to be a difficult task, but I don't know how to turn off the default action associated with a particular key combination, such as "Alt+F" to pop up the "File" menu.

Thanks!

It's been a while, but I assume that bug must have been caused by returning the result of CallNextHook from the hook procedure rather than just returning 1.

Are you subclassing the AutoCAD window, or are you using hooks?
Title: Re: Managed HotKeys
Post by: FengK on June 20, 2008, 01:16:09 PM
It's been a while, but I assume that bug must have been caused by returning the result of CallNextHook from the hook procedure rather than just returning 1.

Thanks Chuck. Is this the line?
return WindowsHook.CallNextHookEx(hHook, code, wParam, lParam);

I don't know how to write the WindowsHook class in Python yet. Maybe there is another way. I have no clue.

Are you subclassing the AutoCAD window, or are you using hooks?

I'm going to use pyHook (http://sourceforge.net/project/showfiles.php?group_id=65529&package_id=92632) to monitor system keyboard event.Not just in AutoCAD, so I need to check if AutoCAD is active. This part is not difficult.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 20, 2008, 02:27:13 PM
Can you post your code?  I can muddle my way through Python code.  I might be able to identify the problem.
Title: Re: Managed HotKeys
Post by: FengK on June 20, 2008, 07:32:20 PM
Can you post your code?  I can muddle my way through Python code.  I might be able to identify the problem.

please see attached. i just started it and it is far from being a completed solution.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 20, 2008, 08:22:36 PM
Can you post your code?  I can muddle my way through Python code.  I might be able to identify the problem.

please see attached. i just started it and it is far from being a completed solution.

I didn't understand all of your code, but I did pick up on a couple of things.  The example program that comes with pyHook says to return False if you don't want the event to propagate to other handlers.  I changed your code in a couple of places.  Where you check to see if AutoCAD is active, you call the pass statement.  I replaced that with "return True."  That way the event will immediately get passed to the next handler, and the hook procedure will stop executing if AutoCAD isn't active.  Then I added "return False" as the last line of your elif clause so that no additional handlers will see the event.  I hope it works for you.

Title: Re: Managed HotKeys
Post by: FengK on June 21, 2008, 04:20:55 AM
Thanks a lot Chuck. I'll test your revision Monday and report back. Have a good weekend.
Title: Re: Managed HotKeys
Post by: FengK on June 23, 2008, 01:44:15 PM
Chuck, your revision worked! Thanks again. Now I'll work on reading the hotkey definition file. For now, I'll just use a text file and the input will be something like

Alt+D COXD
Alt+F LAYERP
Ctrl+Shift+W MAXWIN
...
...

Title: Re: Managed HotKeys
Post by: kdub_nz on July 07, 2009, 02:35:08 AM

Has anyone tried Hotkeys in AC2010.

In 2010 Mechanical the cursor seems to freeze for a few seconds after the shortcut is pressed ...
I haven't tried in Vanilla  will have a look at home tonight ...

Regards
Kerry
Title: Re: Managed HotKeys
Post by: Kerry on July 07, 2009, 04:14:12 AM

Say the definition is ALT+E for _ENDPOINT

The cursor actually locks up.
Press ESC and the selection continues with the correct snap set.

too brain dead to have a further look at it tonight  :|
Title: Re: Managed HotKeys
Post by: FengK on July 07, 2009, 04:25:05 AM
oh, who has the latest version? can you post it here? I tried the link from this post (http://www.theswamp.org/index.php?topic=10570.msg177010#msg177010) and it didn't work. thanks.
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on July 07, 2009, 09:23:21 AM

Say the definition is ALT+E for _ENDPOINT

The cursor actually locks up.
Press ESC and the selection continues with the correct snap set.

too brain dead to have a further look at it tonight  :|

I'm not sure if this is the same problem you are experiencing, but I had a similar problem when I tested on AutoCAD 2009 if the menubar was displayed.  The Alt key was trying to activate the pulldown menus.  Here is the binary that fixes that bug.

Title: Re: Managed HotKeys
Post by: Kerry on July 07, 2009, 04:10:02 PM


Thanks Chuck, works a treat !

Your generosity is truly appreciated.

Regards,
Kerry
Title: Re: Managed HotKeys
Post by: Kerry on June 27, 2010, 06:03:18 AM

Seemed best to resurrect this rather than start a new thread.

Has anyone got a .dll for Hotkeys working in Win 7 64 bit with ACAD2011 ( actually ACADMechanical 2011).

The ac2010 build seems to load without complaining but the commands are not registered.

This is a shiny new box so there are no residuals . (has .Net 4.0 installed )
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 27, 2010, 10:05:24 AM
I wish I could test that for you, but I don't have Windows 7 or AutoCAD 2011.  I wonder if maybe UAC is blocking the required registry changes.
Title: Re: Managed HotKeys
Post by: Kerry on June 27, 2010, 06:00:21 PM

Hello Chuck,
I tried disabling the UAC last night. no joy.

I'll have another look tonight.

Thanks

Kerry.
Title: Re: Managed HotKeys
Post by: mjfarrell on June 27, 2010, 06:13:17 PM
I wonder if the issue is similar to if not the same as the one being resolved here:

http://www.theswamp.org/index.php?topic=19980.msg392352#msg392352 (http://www.theswamp.org/index.php?topic=19980.msg392352#msg392352)
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 27, 2010, 07:21:08 PM

Hello Chuck,
I tried disabling the UAC last night. no joy.

I'll have another look tonight.

Thanks

Kerry.

You've probably already thought of this too, but is the dll on a local drive or a network share?  Also, have you stepped through the entry point in the debugger?

One more thing.  When you said the commands weren't registered, I assumed you meant the demand loading entries weren't added to the registry.  Did you actually mean that the commands don't work even when you manually load the dll?
Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 07:26:32 PM
Hi Kerry, get this working? My guess, its throwing @ IExtensionApplication.Initialize... remind me where the code is and I will look :)
 
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 07:37:09 PM
Hi Daniel
I think this is the latest

http://www.theswamp.org/index.php?topic=31924.msg374004#msg374004

I haven't made time to look at it.
There were no exceptions thrown though ...
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 07:40:39 PM

May be an idea to add something like this to the Initialize()  and the  keysOn() ,  keysOff() <- with 'unloaded' message

                docMan.MdiActiveDocument.Editor.WriteMessage(
                        "\nHotkeys_2010/11 are loaded.\n Commands : KeysOn, KeysOff, KeysToggle, KeysConfig, EditKeys");


Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 09:16:20 PM
Try this one

Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 09:50:08 PM

Thanks Dan

eFilerError
   at
Autodesk.AutoCAD.DatabaseServices.ImpHostApplicationServices.FindFile(String
fileName, Database database, FindFileHint hint)
   at HotKeys.KeysFile.locateKeysFile()
   at HotKeys.AppRegistry.initialize()
   at HotKeys.Main.Initialize()
Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 10:04:43 PM
Great!

We should probable put this in a FAQ somewhere, if you use IExtensionApplication, add a try catch

Code: [Select]
   public void Initialize()
    {
      try
      {
       //todo
      }
      catch (System.Exception ex)
      {
        Autodesk.AutoCAD.ApplicationServices.Application.
          DocumentManager.MdiActiveDocument.Editor.
          WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace);
      }
    }
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:05:16 PM
Looks like the Registry entrys are not being made.
I thought the initial initialize added the entrys if they didn't exist ...

This is the reg after running the netload ..

[added]
and the same under
HKEY_CURRENT_USER\Software\ManagedHotKeys
HKEY_USERS\S-1-5-21-1614435629-549356334-4198987207-1000\Software\ManagedHotKeys
 
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:07:56 PM
Great!

We should probable put this in a FAQ somewhere, if you use IExtensionApplication, add a try catch

Code: [Select]
   public void Initialize()
    {
      try
      {
       //todo
      }
      catch (System.Exception ex)
      {
        Autodesk.AutoCAD.ApplicationServices.Application.
          DocumentManager.MdiActiveDocument.Editor.
          WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace);
      }
    }

Great idea 
If you like I'll add a reference into the 'Getting Started' Series.
Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 10:11:34 PM
where is your xml file?
look under HKEY_CURRENT_USER\Software\ManagedHotKeys
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:15:34 PM
where is your xml file?
look under HKEY_CURRENT_USER\Software\ManagedHotKeys

No entry
as posted in piccy.
Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 10:16:04 PM
From the looks of it, the XML file must be in a search path, or in My documents.. where is yours?
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:19:01 PM
In the same folder as the .DLL  ... NOT on the Search Path
both the default xml and my personal renamed modified xml.


What are your thoughts on this ??
Personally I'd rather not need to modify the Search path.
Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 10:32:01 PM
quick fix, put a file called HotKeys.xml in my documents.
launch Acad and load dll.
use the keysconfig command to locate your personal xml

this should save the setting in the reg.
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:38:53 PM
quick fix, put a file called HotKeys.xml in my documents.
launch Acad and load dll.
use the keysconfig command to locate your personal xml

this should save the setting in the reg.

:)

Just came back to say I'd done exactly that ... and it worked fine.
I'll look at the options when I get a chance ... unless someone beats me to it.

Thanks Dan

Regards
Title: Re: Managed HotKeys
Post by: It's Alive! on June 28, 2010, 10:40:00 PM
@ Chuck -- Rule #1749-5 of the programmers handbook, always test your code on a virgin machine   :lol:
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:42:46 PM
Just as a note for later

the

 (int)AppDomain.GetCurrentThreadId());

is depricated.


[added]
Also for later ..
perhaps a .NET editor for the XML files to replace the current VB6 editor.
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2010, 10:44:18 PM
@ Chuck -- Rule #1749-5 of the programmers handbook, always test your code on a virgin machine   :lol:

They're pretty difficult to find Dan .... virgin machines I mean :)
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on June 28, 2010, 11:19:39 PM
@Daniel - Thanks for helping Kerry with this.  Can I borrow your copy of the handbook?

@Kerry - That function was already deprecated when I first wrote this, but I couldn't get the proposed alternative to work.

The editor could certainly use some updates, but I just can't seem to get motivated to tackle it.
Title: Re: Managed HotKeys
Post by: Kerry on July 04, 2010, 03:31:37 AM
I've made some mods to the KeysFile.cs
The Search procedure for the .XML file is now :-


The changes were to public static String locateKeysFile()
and adding the DllImport for acedFindFile

I cleaned my registry of all ManagedHotkeys references and the INITIAL netload seemed to make the registry entrys without issue.

Have not yet conformed to Rule #1749-5 of the programmers handbook

Code: [Select]

using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Collections;

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using System.Runtime.InteropServices;

namespace HotKeys
{
    public class KeysFile
    {

        private Hashtable m_keyCombos;
        private const String KEYS_FILE_NAME = "HotKeys.xml";

        public KeysFile(Hashtable keyCombos)
        {
            m_keyCombos = keyCombos;
        }

        [DllImport("acad.exe", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
        private static extern int acedFindFile(string fileName, string result);


        public static String locateKeysFile()
        {
            // Will only be called if there is no entry in the registry
            // First, try a Findfile
            // alternatively in the Hotkeys Folder,
            // alternatively in the Documents Folder
            // revised kdub 2010.07.04

            // try a Findfile in the Autocad searchPath, Current drawing Folder
            String qualifiedFileName = string.Empty;
            acedFindFile(KEYS_FILE_NAME, qualifiedFileName);

            // else try in the Hotkeys Folder
            if (qualifiedFileName == "")
            {
                String assemblyName = System.Reflection.Assembly.GetExecutingAssembly().Location;
                String appDir = Path.GetDirectoryName(assemblyName);
                String fn = appDir + "/" + KEYS_FILE_NAME;

                if (System.IO.File.Exists(fn))
                    qualifiedFileName = fn;
            }

            // else try  in the Documents Folder
            if (qualifiedFileName == "")
            {
                String docFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                String[] fileNames = Directory.GetFiles(docFolder, KEYS_FILE_NAME, SearchOption.TopDirectoryOnly);
                if (fileNames.Length != 0)
                    qualifiedFileName = fileNames[0];
            }

            if (qualifiedFileName != "")
                AppRegistry.keysFileName = qualifiedFileName;
            return qualifiedFileName;
        }

        public bool reload()
        {
            String keysFileName = AppRegistry.keysFileName;
            if ((keysFileName == "") || !File.Exists(keysFileName))
                keysFileName = locateKeysFile();
            if (keysFileName == "")
                return false;

            m_keyCombos.Clear();

            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.Load(keysFileName);

            XmlElement root = doc.DocumentElement;
            XmlNodeList hotKeyElements = root.GetElementsByTagName("HotKey");
            int len = hotKeyElements.Count;
            foreach (XmlElement element in hotKeyElements)
            {
                XmlNode nodeModifiers = element.GetElementsByTagName("Modifiers").Item(0);
                UInt16 modifiers = XmlConvert.ToUInt16(nodeModifiers.InnerText);
                XmlNode nodeVkey = element.GetElementsByTagName("VirtualKey").Item(0);
                UInt16 virtualKey = XmlConvert.ToUInt16(nodeVkey.InnerText);
                UInt32 keyCombo = (UInt32)virtualKey | ((UInt32)modifiers << 16);
                if (!m_keyCombos.ContainsKey(keyCombo))
                {
                    XmlNode nodeCommand = element.GetElementsByTagName("Command").Item(0);
                    StringBuilder command = new StringBuilder(nodeCommand.InnerText);
                    command.Replace('|', '\n');
                    m_keyCombos.Add(keyCombo, command.ToString());
                }
            }
            return true;
        }
    }
}



I've also made changes to the  Initialize() method in Main.cs to notify the user of the defined Commands.

Code: [Select]
   public void Initialize()
    {
      try
      {        
        AppRegistry.initialize();
        allowCapsLockMod = AppRegistry.allowCapsLockMod;
        kbdHook.Install();
        msgHook.Install();
        keysOn();
        docMan.MdiActiveDocument.Editor.WriteMessage(
                "\nHotkeys_2010 are loaded.\n  Commands: KeysOn, KeysOff, KeysToggle, KeysConfig, EditKeys");
      }
      catch (System.Exception ex)
      {
        docMan.MdiActiveDocument.Editor.WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace);

      }

    }


Title: Re: Managed HotKeys
Post by: Chuck Gabriel on July 04, 2010, 08:25:54 AM
Your version is now trunk.  That makes you the official maintainer.  Congratulations! :-)
Title: Re: Managed HotKeys
Post by: Kerry on July 04, 2010, 08:36:26 AM


Whoa ... how did that happen ??   :)

I'll repost the solution when I'm happy with the changes I've made.
Won't get to look at it for a couple of days though.



Title: Re: Managed HotKeys
Post by: It's Alive! on July 04, 2010, 08:43:19 AM
 :lol:
Title: Re: Managed HotKeys
Post by: Kerry on July 04, 2010, 08:46:41 AM

This is a sort of musical chairs using code, right ??
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on July 04, 2010, 08:59:17 AM
Don't forget to change the name and email address in the documentation. ;-p
Title: Re: Managed HotKeys
Post by: It's Alive! on July 04, 2010, 09:30:14 AM
Is this on swamp's SVN? might be a good place for it.
Title: Re: Managed HotKeys
Post by: sinc on July 04, 2010, 11:17:45 AM

They're pretty difficult to find Dan .... virgin machines I mean :)

Why does Frank Zappa suddenly spring to mind?   :-)
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on July 05, 2010, 03:20:38 PM
(int)AppDomain.GetCurrentThreadId());

is depricated.

System.Threading.Thread.CurrentThread.ManagedThreadId is what the compiler suggests in lieu of AppDomain.GetCurrentThreadId().  I can't remember for certain if that is what I tried.  Wanna give it a go?
Title: Re: Managed HotKeys
Post by: Kerry on July 05, 2010, 05:09:51 PM
(int)AppDomain.GetCurrentThreadId());

is depricated.

System.Threading.Thread.CurrentThread.ManagedThreadId is what the compiler suggests in lieu of AppDomain.GetCurrentThreadId().  I can't remember for certain if that is what I tried.  Wanna give it a go?


I had a quick look last weekend Chuck, but need to do a lot more investigation.
Title: Re: Managed HotKeys
Post by: Jeff Moran on November 15, 2010, 01:16:10 PM

Say the definition is ALT+E for _ENDPOINT

The cursor actually locks up.
Press ESC and the selection continues with the correct snap set.

too brain dead to have a further look at it tonight  :|

I'm not sure if this is the same problem you are experiencing, but I had a similar problem when I tested on AutoCAD 2009 if the menubar was displayed.  The Alt key was trying to activate the pulldown menus.  Here is the binary that fixes that bug.



Chuck,

Would you happen to still have the source for this binary? Or could you share what you did to solve the problem. The binary didn't work with my 2011.

Thanks in advance!
Jeff
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on November 16, 2010, 11:51:46 PM

Say the definition is ALT+E for _ENDPOINT

The cursor actually locks up.
Press ESC and the selection continues with the correct snap set.

too brain dead to have a further look at it tonight  :|

I'm not sure if this is the same problem you are experiencing, but I had a similar problem when I tested on AutoCAD 2009 if the menubar was displayed.  The Alt key was trying to activate the pulldown menus.  Here is the binary that fixes that bug.



Chuck,

Would you happen to still have the source for this binary? Or could you share what you did to solve the problem. The binary didn't work with my 2011.

Thanks in advance!
Jeff

That fix should be in the latest version (whatever that may be).  Kerry (and perhaps others) has made improvements to the code since I last touched it, and I would recommend working from his version rather than anything as stale as the version where that fix was originally made.

If Kerry doesn't want to make his changes publicly available, I will post my most recent source code.  Be warned, however, that it doesn't contain any of Kerry's enhancements, and I may have done some playing and left the code in an unstable state.  I honestly can't remember what I last did to it, but I know I piddled around with it a little about the time of my last post to this thread.
Title: Re: Managed HotKeys
Post by: Kerry on November 17, 2010, 12:06:15 AM

I'll post my source from home tonight gents.

I started to build a .net version of the editor but life gets in the way my of finishing it.

The current editor is VB6 based and may requre the registration of components.

If necessary I can make changes to the XML file for anyone who has problems.
.... may be a good chance to explain the actual structure :)

regards
kdub.
Title: Re: Managed HotKeys
Post by: Kerry on November 17, 2010, 06:49:21 AM
Here we go !

Title: Re: Managed HotKeys
Post by: Jeff Moran on November 18, 2010, 03:37:21 PM
Thanks Guys!
Title: Re: Managed HotKeys
Post by: Jeff Moran on November 18, 2010, 03:43:15 PM
Oops!
I forgot to say it works great!
Thanks again!
Title: Re: Managed HotKeys
Post by: Tom on May 30, 2012, 05:46:42 PM
Has anyone done a compile for 2013 they can post?
Title: Re: Managed HotKeys
Post by: Kerry on May 30, 2012, 06:10:34 PM

I was planning on doing one over the weekend Tom.

Regards
Title: Re: Managed HotKeys
Post by: Chuck Gabriel on May 30, 2012, 06:47:17 PM
Remind me to give you a raise. :-)
Title: Re: Managed HotKeys
Post by: Kerry on May 31, 2012, 04:30:35 AM

OK :-D
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 12:53:57 PM
Just came across this thread for the first time, and HotKeys sounds really interesting.

I downloaded Kerry's files from here (http://www.theswamp.org/index.php?topic=10570.msg409779#msg409779), and Netloaded the ..\Release\*.dll (which seems to load fine), yet I am apparently missing something:

Code: [Select]
Command: editkeys

Editor not found.

Is there any one place to acquire the full application (i.e., all files needed), or do I need to piece-meal it from the previous 8 pages?

FWIW... Using Civil 3D 2011, and 2012.

**Edit - Just remembered the post(s) about editing the XML manually... Perhaps I'm just doing this wrong... Do I modify the HOTKEYS.XML file (or a copy of)? And if so, what does VirtualKey 88 correlate to on the keyboard (for example)? *lost*

TIA
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 01:08:44 PM
I downloaded Kerry's files from here (http://www.theswamp.org/index.php?topic=10570.msg409779#msg409779), and Netloaded the ..\Release\*.dll (which seems to load fine), yet I am apparently missing something:

Code: [Select]
Command: editkeys

Editor not found.

*Doh!* - After reading 9 pages, I forgot this in the first post :lol: :

The editor isn't in the zip file, so expect the editkeys command to flop if you don't already have an older version of HotKeys installed.
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 01:24:20 PM
**Edit - Just remembered the post(s) about editing the XML manually... Perhaps I'm just doing this wrong... Do I modify the HOTKEYS.XML file (or a copy of)? And if so, what does VirtualKey 88 correlate to on the keyboard (for example)? *lost*

Okay, I did the responsible thing, and Google VirtualKey codes for myself, and found this (http://www.indigorose.com/webhelp/ams/Program_Reference/Misc/Virtual_Key_Codes.htm), which is helpful.

However, An attempt to activate this HotKey:

Code: [Select]
  <HotKey>
    <!--Alt ???-->
    <Modifiers>1</Modifiers>
    <!--C ???-->
    <VirtualKey>67</VirtualKey>
    <Command>_CEN </Command>
  </HotKey>

... Results in a fatal error; what am I missing???  :? (HotKeys Noob)
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 01:50:08 PM
Now I've done it... Ever since the first fatal error, Civil 3D isn't even starting properly. If I do get it to start without immediately having a fatal error, this is the error I get:

I've tried deleting all of the registry keys for ManagedHotKeys, and Civil 3D still won't work properly.  :pissed:
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 02:55:00 PM
I was seriously freaking out... Not sure how/why, but apparently Communication Center was causing this error (not sure if HotKeys interacts with that or not, really?).

Came across this thread (http://forums.autodesk.com/t5/AutoCAD-Civil-3D/FATAL-ERROR-unhandled-e06d7363h-Exception-at-75c99617h/m-p/2746151#M135700) (post #9), changed the registry key to 18.1 (2011), and manually edited the "LastUpdateTimeLoWord" DWord = 0.



Now that that is taken care of...

If necessary I can make changes to the XML file for anyone who has problems.
.... may be a good chance to explain the actual structure :)

... Yes, please. *raises hand* :-D
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 03:55:03 PM
While there are several warnings, the solution does build successfully.

I've made a minor code update in an effort to prevent fatal errors when I invoke a HotKey:

Code - C#: [Select]
  1.         public void Install()
  2.         {
  3.             m_hHook = SetWindowsHookEx(
  4.                 m_hookType,
  5.                 m_hookProc,
  6.                 IntPtr.Zero,
  7.                 //(int)AppDomain.GetCurrentThreadId());
  8.                 (int)System.Threading.Thread.CurrentThread.ManagedThreadId);
  9.         }
  10.  

The resultant build does load fine, and also prevents the previous fatal errors, however, the HotKeys are not functional.

When attempting to use Alt + C (for _CEN), the Menubar is activated as though you only pressed Alt. Menubar=0 results in the Alt options for the ribbon. Closing the Ribbon results in the Alt options for the Quick Access Toolbar (QAT). Removing all items from the QAT results in the Alt option for the Menu Browser.

*stuck*
Title: Re: Managed HotKeys
Post by: Kerry on May 31, 2012, 05:02:05 PM


Renderman,
I don't have C3D on any of my machines.

I made changes last night and recompiled for 2013.
The basic app works fine in vanilla AutoCAD when netloaded.
I just need to make the required changes to the registry read/write code ( due to API changes).

Sounds like it's time to pull my finger out and re-write the editor as well ... perhaps it's a good excuse for a full re-write.

Regards
Kerry
Title: Re: Managed HotKeys
Post by: BlackBox on May 31, 2012, 06:54:04 PM
Understood... I'd be happy to contribute at your discretion (Civil 3D, Map 3D, and AMEP debugging, etc., as I am learning to code in C# for my night job), and learn (from someone much, much smarter than I) at the same time.! LoL

Cheers, Kerry!
Title: Re: Managed HotKeys
Post by: Jeff H on June 09, 2012, 12:47:48 AM

Sounds like it's time to pull my finger out and re-write the editor as well ... perhaps it's a good excuse for a full re-write.
Kerry if you do a re-write would you use the Application.PreTranslateMessage event or would that work here?
 
They show this as correct way here (http://adndevblog.typepad.com/autocad/2012/06/reacting-to-the-cursor-keys-properly-without-affecting-autocad-using-net.html) but seemed as easy here (http://www.theswamp.org/index.php?topic=39118.msg443316#msg443316)
Title: Re: Managed HotKeys
Post by: Kerry on June 09, 2012, 03:42:41 AM

I hadn't really thought it through Jeff.
I really wanted to do without the hoops needed to write the alias file ... looking for a way that wouldn't require so much translation.

... I need to cross one creek at a time though :)
Title: Re: Managed HotKeys
Post by: BlackBox on June 09, 2012, 12:24:53 PM

Sounds like it's time to pull my finger out and re-write the editor as well ... perhaps it's a good excuse for a full re-write.
Kerry if you do a re-write would you use the Application.PreTranslateMessage event or would that work here?
 
They show this as correct way here (http://adndevblog.typepad.com/autocad/2012/06/reacting-to-the-cursor-keys-properly-without-affecting-autocad-using-net.html) but seemed as easy here (http://www.theswamp.org/index.php?topic=39118.msg443316#msg443316)

Thanks for the reminder, Jeff - I got so busy with work that I neglected to pick that task back up (the 2nd link). Also, thanks for the DevBlog link as well.   :-)
Title: Re: Managed HotKeys
Post by: Tom on June 28, 2012, 05:08:29 PM
"Has anyone done a compile for 2013 they can post?" Bump
Title: Re: Managed HotKeys
Post by: Kerry on June 28, 2012, 11:36:20 PM

Tom,
I've built it and had it running but my 2013 has issues and I haven't finished testing.
I'll rebuild it on my laptop over the weekend and try to finish testing.
Regards
Kerry
Title: Re: Managed HotKeys
Post by: BlackBox on June 29, 2012, 08:48:10 AM
Kerry -

Only because you mentioned having 2013 'working', would you by chance have the 2010 build available for those of us stuck back with 2010-2012 apps?  :angel:
Title: Re: Managed HotKeys
Post by: Kerry on June 29, 2012, 10:36:01 AM
Kerry -

Only because you mentioned having 2013 'working', would you by chance have the 2010 build available for those of us stuck back with 2010-2012 apps?  :angel:

Here we go !

http://www.theswamp.org/index.php?topic=10570.msg409779#msg409779


and to play with:
Title: Re: Managed HotKeys
Post by: BlackBox on June 29, 2012, 11:48:18 AM
That build doesn't work (http://www.theswamp.org/index.php?topic=10570.msg469979#msg469979)... That's why I asked again. :wink:

** Edit - Just saw that you added some attachments... Off to play. :lol:
Title: Re: Managed HotKeys
Post by: BlackBox on June 29, 2012, 12:10:01 PM
That build doesn't work (http://www.theswamp.org/index.php?topic=10570.msg469979#msg469979)... That's why I asked again. :wink:


... Same as before. It's not working.  :|

Civil 3D 2011, 2012.
Title: Re: Managed HotKeys
Post by: Kerry on June 29, 2012, 07:23:31 PM
That build doesn't work (http://www.theswamp.org/index.php?topic=10570.msg469979#msg469979)... That's why I asked again. :wink:

** Edit - Just saw that you added some attachments... Off to play. :lol:

I don't have Civil to test against.
That version is the same build date  I'm using sucessfully for AC2012 Vanilla.
Title: Re: Managed HotKeys
Post by: Tom on July 26, 2012, 05:19:08 PM
"Has anyone done a compile for 2013 they can post?" Bump
Title: Re: Managed HotKeys
Post by: CADDee on October 25, 2012, 10:16:35 AM
Kerry,

I tracked down Chuck Gabriel and he informed that you are now the keeper of the most useful tool ever written for AutoCAD.

I'm finally getting around to upgrading to 2013, and I realized that Hotkeys is broken again.

So all of my desperate measures have lead me to this post, where I can see others are asking for an update too.

Did you ever get the Hotkeys.dll to load without errors and can you please share?

Thank you in advance!
Jim Dee
Title: Re: Managed HotKeys
Post by: Jeff_M on August 23, 2013, 07:51:06 PM
BTW BlackBox/Renderman, I was able to load and use the Hotkeys[2010] in C3D2012 without a problem.
Title: Re: Managed HotKeys
Post by: BlackBox on August 24, 2013, 03:00:20 AM
BTW BlackBox/Renderman, I was able to load and use the Hotkeys[2010] in C3D2012 without a problem.

I was having issues with loadin in Civil 3D 2011 previously, and now also have 2012 installed, although we're gearin up for 2014. With only a few project in 2012, we may jut skip it so to speak.

I have 2014 suite installed at home (ADN), and will see if I cannot get it to work there for upgrade time at work.

Thanks for confirmin though that its working for you in 2012; I appreciate it.

Cheers
Title: Re: Managed HotKeys
Post by: Jeff_M on August 24, 2013, 04:49:25 AM
2013 is a whole different story. It builds and loads fine, after some edits,  but FE's shortly thereafter.
Title: Re: Managed HotKeys
Post by: Kerry on August 24, 2013, 06:53:10 AM
I isolated the cause of the issue to the new command line technology used in 2013.
Discussions with ADN were unable to resolve the issue. I put the build aside and haven't looked at it since.

Quote from: me
I get AutoCAD crashes when I use Ctrl-V, Ctrl-C etc  when either the Command line or VLIDE have focus.
This does not happened prior to 2013.