views:

31

answers:

0

I have this problem using MDX: i am trying to set up a keyboard device with the Foreground and Exclusive flags (up until now I let it to Background - which worked - and did the KeyUp / KeyDown events only when the app was focused, but with these settings I recon you can get some antivirus alerts because it could think that the app is a keylogger).

The problem is the device fails to acquire with the "DirectInput.CooperativeLevelFlags.Foreground | DirectInput.CooperativeLevelFlags.Exclusive" settings and i have no idea why. Can you help me?

the code for the device initialization is:

private bool InitializeKeyboard(Game game)
    {
        try
        {
            Keyboard = new DirectInput.Device(DirectInput.SystemGuid.Keyboard);
            Keyboard.SetCooperativeLevel(game,
                 DirectInput.CooperativeLevelFlags.Foreground | DirectInput.CooperativeLevelFlags.Exclusive);
            Keyboard.Acquire();
        }

where 'game' is the main form of the app. the specific function that fails in that block is Keyboard.Acquire();