Author Topic: detecting CTRL+Z  (Read 2037 times)

0 Members and 1 Guest are viewing this topic.

jsr

  • Guest
detecting CTRL+Z
« on: January 20, 2011, 12:19:27 AM »
Hi all

Using .NET api how can we detect if user has pressed CTRL+Z (undo) in a command. For example while creating a polyline etc. Is their any event available for this.

Thanks.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: detecting CTRL+Z
« Reply #1 on: January 20, 2011, 12:43:30 AM »
There is a method to intercept keypress events when any winform is displayed, all you need to do is capture the event and filter for the specific key. You can also get the last key pressed using an API call, but I don't recall what it is at the moment.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

jsr

  • Guest
Re: detecting CTRL+Z
« Reply #2 on: January 20, 2011, 01:00:04 AM »
Thanks Keith

Is their any support available for same in AutoCAD .NET api (not the .NET api as a whole). For example we can detect key presses using PointMonitor event handler but this does not seem to work for CTRL+Z.

Thanks again.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: detecting CTRL+Z
« Reply #3 on: January 20, 2011, 01:29:55 AM »
I don't think so, and I am pretty sure that system-wide keyboard hooks aren't supported in .NET ... you could probably create a thread that monitors the keyboard through simple polling, but then you would probably have problems in the long run due to timing issues since it wouldn't be an event driven thread.

It sounds like you are wanting to monitor AutoCAD for a specific condition to happen ... I'm not sure you can do that with .NET
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Jeff H

  • Needs a day job
  • Posts: 6150
Re: detecting CTRL+Z
« Reply #4 on: January 20, 2011, 02:32:32 AM »
Add reference to WindowBase

Seems to fire before any other command and fires during active commands



Code: [Select]


        const int WM_CHAR = 258;

        [CommandMethod("AddCtrlZEventHandler")]

        public void AddCtrlZEventHandler()
        {

            Application.PreTranslateMessage +=

              new PreTranslateMessageEventHandler(CtrlZHandler);

        }


        void CtrlZHandler(object sender, PreTranslateMessageEventArgs e)
        {

            if (e.Message.message == WM_CHAR && e.Message.wParam.ToInt32() == 26)
            {
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCtrl-Z is pressed\n");

            }

        }




This code with the 3 changed to 26
http://through-the-interface.typepad.com/through_the_interface/2008/05/filtering-windo.html





jsr

  • Guest
Re: detecting CTRL+Z
« Reply #5 on: January 20, 2011, 02:47:58 AM »
Thanks alot Jeff.

kaefer

  • Guest
Re: detecting CTRL+Z
« Reply #6 on: January 20, 2011, 03:01:06 AM »
It sounds like you are wanting to monitor AutoCAD for a specific condition to happen ... I'm not sure you can do that with .NET

I'd say he wants to monitor AutoCAD for a specific condition to happen.
Quote
Using .NET api how can we detect if user has pressed CTRL+Z (undo) in a command. For example while creating a polyline etc. Is their any event available for this.

The conditions as I read them are that we're in the PLINE command, and a specific key combo is pressed. The CommandWillStart event allows for the former, and a MessageFilter should do the latter. Besides, we need handlers for CommandCancelled, CommandEnded, CommandFailed, DocumentCreated and DocumentToBeDestroyed to make it work.

Of course it's not really a good idea anyway to change the semantics of an existing command.