Author Topic: Managed HotKeys  (Read 53902 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Managed HotKeys
« Reply #105 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 :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: Managed HotKeys
« Reply #106 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Managed HotKeys
« Reply #107 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 :-

  • Registry. (use fileName stored)
  • Findfile for default fileName <Hotkeys.xml> (via a p'invoked call) searching the AutoCAD search path & etc.
  • The Hotkeys assembly folder  for default fileName .
  • The Documents folder  for default fileName  ... not subfolders.

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);

      }

    }


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: Managed HotKeys
« Reply #108 on: July 04, 2010, 08:25:54 AM »
Your version is now trunk.  That makes you the official maintainer.  Congratulations! :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Managed HotKeys
« Reply #109 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.



kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Managed HotKeys
« Reply #110 on: July 04, 2010, 08:43:19 AM »
 :lol:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Managed HotKeys
« Reply #111 on: July 04, 2010, 08:46:41 AM »

This is a sort of musical chairs using code, right ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Chuck Gabriel

  • Guest
Re: Managed HotKeys
« Reply #112 on: July 04, 2010, 08:59:17 AM »
Don't forget to change the name and email address in the documentation. ;-p

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: Managed HotKeys
« Reply #113 on: July 04, 2010, 09:30:14 AM »
Is this on swamp's SVN? might be a good place for it.

sinc

  • Guest
Re: Managed HotKeys
« Reply #114 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?   :-)

Chuck Gabriel

  • Guest
Re: Managed HotKeys
« Reply #115 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?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Managed HotKeys
« Reply #116 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.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Jeff Moran

  • Guest
Re: Managed HotKeys
« Reply #117 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

Chuck Gabriel

  • Guest
Re: Managed HotKeys
« Reply #118 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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Managed HotKeys
« Reply #119 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.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.