-2

whenever i am pressing key in my server system i ll send that keyevent to another system after that the correspondingaction should be happend in the client machine.. help me to get a better way to solve this problem

thanx in advance

mezoid
  • 28,090
  • 37
  • 107
  • 148
RV.
  • 2,782
  • 8
  • 39
  • 51

2 Answers2

1

please give us more details on what you're trying to do. To simulate key presses in Windows Forms, I'd use SendKeys class.

Valentin V
  • 24,971
  • 33
  • 103
  • 152
1

If I understand it correctly then what you have doesn't sound too bad. Are you saying that:

  • You have a client server architecture.
  • At the server (presumably at command console or management application) you press a key.
  • The key corresponds to an action. The action needs to be invoked at the client.

You could implement this using asynchronous WCF. See here and here for more some more info. One way to look at this problem is as a distributed observer pattern. Your server is the subject and the client(s) are the observer(s).


Update: Handling Key Events in .Net

You could try adding a KeyDown event handler to your form:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Control & e.KeyCode == Keys.C)
    {
        MessageBox.Show( "Ctrl + C pressed" );
        // Swallow key event, i.e. indicate that it was handled.
        e.Handled = true;
    }
}

But if you have any controls on your form then you won't get the event. What you probably need to do is sniff windows messages using a message filter. E.g.

public class KeyDownMessageFilter : IMessageFilter
{
    public const int WM_KEYDOWN = 0x0100;

    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_KEYDOWN)
        {
            // Key Down
            return true; // Event handled
        }
        return false;
    }
}

Add this message filter to the application using the AddMessageFilter method. If you want to check if the CTRL key is pressed for the key down message then check the lparam.

If any of this isn't clear then let me know.

Community
  • 1
  • 1
ng5000
  • 12,330
  • 10
  • 51
  • 64
  • can you tell me how to get combination of key from my application like Ctrl+c Ctrl+v etc.... – RV. Feb 20 '09 at 12:05