INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: MobyFrag: Key Handling  (Read 2657 times)

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
MobyFrag: Key Handling
« on: January 29, 2006, 09:12:35 am »

I've been mainly working under C# and I don't do much C++ but I think
theoretically it should work.
Under C# I was having problems detecting all keys except letters.
I found a small post written by some genius deep in the depths of cyberspace
about overwriting wndproc.
In C# the code looks like this

protected override void WndProc(ref System.Windows.Forms.Message m)
{   
   //If Key Down is detected and that key is Enter
   if (m.Msg== 0x0100 && m.WParam==(Keys.Enter))
   {
      //Do What we are going to do with the key
      myEnterKeyFunction

      //Set our result indicating the key press is sorted
      m.Result = new IntPtr(0);
     
   }
   //Otherwise We are not interested
   else
   {
      //Send this back to the depths from wence it came.
      base.WndProc(ref m);
   }
}

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: MobyFrag: Key Handling
« Reply #1 on: January 29, 2006, 09:14:54 am »

In C++ You have a main message loop
which should remain running after everything else has been
initialised
In some DirectX work I've been doing recently under C++
it looks something like this

MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
   // check for messages
   if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
   {
      TranslateMessage( &msg );
      DispatchMessage( &msg );
   }
   // this is called when no messages are pending
   else
   {
      // call our render function
      this->ourScenario->RenderWorld();
   }
}

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: MobyFrag: Key Handling
« Reply #2 on: January 29, 2006, 09:17:32 am »

Theoretically it should be possible to merge those
two and detect the key presses in C++
You'll have to try it though because I'm seriously short of time
at the moment.  2 x 2500 word reports in for the end of the week :-S
If you post a question here I may be able to help though :-)

I've been using this method for a new version of my C# Script Plugin
which will be released over the next few days.  It's written in C# under .NET
framework 2.0

mobyfrag

  • World Citizen
  • ***
  • Posts: 110
Re: MobyFrag: Key Handling
« Reply #3 on: January 30, 2006, 12:38:38 pm »

Thank you very much, for the explanations and the code!
I will test that as soon as I can…  :P

Good day.
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: MobyFrag: Key Handling
« Reply #4 on: February 05, 2006, 09:24:17 am »

I've just hit a problem where the above
soloution does not appear to work.
So you may still have problems with this :-S

mobyfrag

  • World Citizen
  • ***
  • Posts: 110
Re: MobyFrag: Key Handling
« Reply #5 on: February 09, 2006, 02:11:22 pm »

Yes I have...  :-[
Logged
Pages: [1]   Go Up