本文整理汇总了C#中Joystick.SetCooperativeLevel方法的典型用法代码示例。如果您正苦于以下问题:C# Joystick.SetCooperativeLevel方法的具体用法?C# Joystick.SetCooperativeLevel怎么用?C# Joystick.SetCooperativeLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joystick
的用法示例。
在下文中一共展示了Joystick.SetCooperativeLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public static void Initialize()
{
if (dinput == null)
dinput = new DirectInput();
Devices = new List<GamePad>();
foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName);
if (device.ProductName.Contains("XBOX 360"))
continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput)
var joystick = new Joystick(dinput, device.InstanceGuid);
joystick.SetCooperativeLevel(GlobalWin.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
joystick.Acquire();
GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick);
Devices.Add(p);
}
}
示例2: NesVSUnisystemDIPJoystickConnection
public NesVSUnisystemDIPJoystickConnection(IntPtr handle, string guid, IInputSettingsVSUnisystemDIP settings)
{
DirectInput di = new DirectInput();
joystick = new Joystick(di, Guid.Parse(guid));
joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
if (settings.CreditServiceButton != "")
CreditServiceButton = ParseKey(settings.CreditServiceButton);
if (settings.DIPSwitch1 != "")
DIPSwitch1 = ParseKey(settings.DIPSwitch1);
if (settings.DIPSwitch2 != "")
DIPSwitch2 = ParseKey(settings.DIPSwitch2);
if (settings.DIPSwitch3 != "")
DIPSwitch3 = ParseKey(settings.DIPSwitch3);
if (settings.DIPSwitch4 != "")
DIPSwitch4 = ParseKey(settings.DIPSwitch4);
if (settings.DIPSwitch5 != "")
DIPSwitch5 = ParseKey(settings.DIPSwitch5);
if (settings.DIPSwitch6 != "")
DIPSwitch6 = ParseKey(settings.DIPSwitch6);
if (settings.DIPSwitch7 != "")
DIPSwitch7 = ParseKey(settings.DIPSwitch7);
if (settings.DIPSwitch8 != "")
DIPSwitch8 = ParseKey(settings.DIPSwitch8);
if (settings.CreditLeftCoinSlot != "")
CreditLeftCoinSlot = ParseKey(settings.CreditLeftCoinSlot);
if (settings.CreditRightCoinSlot != "")
CreditRightCoinSlot = ParseKey(settings.CreditRightCoinSlot);
NesEmu.EMUShutdown += NesEmu_EMUShutdown;
}
示例3: GetJoystick
private Joystick GetJoystick()
{
var directInput = new DirectInput();
var form = new Form();
foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
var controller = new Joystick(directInput, device.InstanceGuid);
controller.SetCooperativeLevel(form.Handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
var retries = 0;
while (controller.Acquire().IsFailure)
{
retries++;
if (retries > 500)
throw new Exception("Couldnt acquire SlimDX stick");
}
if (controller.Information.InstanceName.Contains("PPJoy"))
{
foreach (DeviceObjectInstance deviceObject in controller.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
controller.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
return controller;
}
}
return null;
}
示例4: Reconnect
public override void Reconnect()
{
// search for devices
foreach (DeviceInstance device in _DInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
// create the device
try
{
_Joy = new Joystick(_DInput, device.InstanceGuid);
_Joy.SetCooperativeLevel(wnd_int, CooperativeLevel.Nonexclusive | CooperativeLevel.Background);
break;
}
catch (DirectInputException)
{
}
}
if (_Joy == null)
{
IsConnected = false;
Name = "";
Type = "";
return;
}
_Joy.Acquire();
IsConnected = true;
Name = _Joy.Information.ProductName;
Type = "DirectInput";
}
示例5: MainController
public MainController()
{
var directInput = new DirectInput();
LogicState = new LogicState();
foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
try
{
gamepad = new Joystick(directInput, deviceInstance.InstanceGuid);
gamepad.SetCooperativeLevel(Parent, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
break;
}
catch (DirectInputException) { }
}
if (gamepad == null)
return;
foreach (var deviceObject in gamepad.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
gamepad.GetObjectPropertiesById((int) deviceObject.ObjectType).SetRange(-1000, 1000);
}
gamepad.Acquire();
}
示例6: NesJoypadPcJoystickConnection
public NesJoypadPcJoystickConnection(IntPtr handle, string guid, IInputSettingsJoypad settings)
{
DirectInput di = new DirectInput();
joystick = new Joystick(di, Guid.Parse(guid));
joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
if (settings.ButtonUp != "")
KeyUp = ParseKey(settings.ButtonUp);
if (settings.ButtonDown != "")
KeyDown = ParseKey(settings.ButtonDown);
if (settings.ButtonLeft != "")
KeyLeft = ParseKey(settings.ButtonLeft);
if (settings.ButtonRight != "")
KeyRight = ParseKey(settings.ButtonRight);
if (settings.ButtonStart != "")
KeyStart = ParseKey(settings.ButtonStart);
if (settings.ButtonSelect != "")
KeySelect = ParseKey(settings.ButtonSelect);
if (settings.ButtonA != "")
KeyA = ParseKey(settings.ButtonA);
if (settings.ButtonB != "")
KeyB = ParseKey(settings.ButtonB);
if (settings.ButtonTurboA != "")
KeyTurboA = ParseKey(settings.ButtonTurboA);
if (settings.ButtonTurboB != "")
KeyTurboB = ParseKey(settings.ButtonTurboB);
}
示例7: DirectInputManager
public DirectInputManager()
{
var directInput = new DirectInput();
// Prefer a Driving device but make do with fallback to a Joystick if we have to
var deviceInstance = FindAttachedDevice(directInput, DeviceType.Driving);
if (null == deviceInstance)
deviceInstance = FindAttachedDevice(directInput, DeviceType.Joystick);
if (null == deviceInstance)
throw new Exception("No Driving or Joystick devices attached.");
joystickType = (DeviceType.Driving == deviceInstance.Type ? JoystickTypes.Driving : JoystickTypes.Joystick);
// A little debug spew is often good for you
Log.Spew("First Suitable Device Selected \"" + deviceInstance.InstanceName + "\":");
Log.Spew("\tProductName: " + deviceInstance.ProductName);
Log.Spew("\tType: " + deviceInstance.Type);
Log.Spew("\tSubType: " + deviceInstance.Subtype);
// Data for both Driving and Joystick device types is received via Joystick
joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
IntPtr consoleWindowHandle = GetConsoleWindow();
if (IntPtr.Zero != consoleWindowHandle)
{
CooperativeLevel cooperativeLevel = CooperativeLevel.Background | CooperativeLevel.Nonexclusive;
Log.Spew("Console window cooperative level: " + cooperativeLevel);
if (!joystick.SetCooperativeLevel(consoleWindowHandle, cooperativeLevel).IsSuccess)
throw new Exception("Failed to set cooperative level for DirectInput device in console window.");
}
var result = joystick.Acquire();
if (!result.IsSuccess)
throw new Exception("Failed to acquire DirectInput device.");
Log.Spew("Joystick acquired.");
}
示例8: Acquire
public void Acquire(Form parent)
{
var dinput = new DirectInput();
Pad = new Joystick(dinput, Guid);
foreach (DeviceObjectInstance doi in Pad.GetObjects(ObjectDeviceType.Axis))
{
Pad.GetObjectPropertiesById((int) doi.ObjectType).SetRange(-5000, 5000);
}
Pad.Properties.AxisMode = DeviceAxisMode.Absolute;
Pad.SetCooperativeLevel(parent, (CooperativeLevel.Nonexclusive | CooperativeLevel.Background));
ButtonCount = Pad.Capabilities.ButtonCount;
Pad.Acquire();
}
示例9: Initialize
public override void Initialize()
{
buttonDown = -1;
joystickIsReady = false;
// Make sure that DirectInput has been initialized
DirectInput dinput = new DirectInput();
state = new JoystickState();
// search for devices
foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
// create the device
try
{
joystick = new Joystick(dinput, device.InstanceGuid);
joystick.SetCooperativeLevel(Core.Settings.RenderForm.Handle,
CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
break;
}
catch (DirectInputException)
{
}
}
if (joystick != null)
{
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
}
}
else
{
return;
}
// acquire the device
joystick.Acquire();
timer = new Timer();
timer.Interval = 1000 / 10;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
示例10: CreateGlobal
public override object CreateGlobal()
{
var directInput = new DirectInput();
var handle = Process.GetCurrentProcess().MainWindowHandle;
devices = new List<Device>();
foreach (var device in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
var controller = new Joystick(directInput, device.InstanceGuid);
controller.SetCooperativeLevel(handle, CooperativeLevel.Exclusive | CooperativeLevel.Background);
controller.Acquire();
devices.Add(new Device(controller));
}
return devices.Select(d => new JoystickGlobal(d)).ToArray();
}
示例11: CreateDevice
void CreateDevice()
{
// make sure that DirectInput has been initialized
DirectInput dinput = new DirectInput();
// search for devices
foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
{
// create the device
try
{
joystick = new Joystick(dinput, device.InstanceGuid);
joystick.SetCooperativeLevel(this, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
break;
}
catch (DirectInputException)
{
}
}
if (joystick == null)
{
MessageBox.Show("There are no joysticks attached to the system.");
return;
}
foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
{
if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
{
joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(0, 255);
}
UpdateControl(deviceObject);
}
// acquire the device
joystick.Acquire();
// set the timer to go off 12 times a second to read input
// NOTE: Normally applications would read this much faster.
// This rate is for demonstration purposes only.
timer.Interval = 5; // 1000 / 1000;
timer.Start();
}
示例12: Input
public Input(Game game, IntPtr handle)
: base(game, -10000)
{
_directInput = new DirectInput();
_keyboard = new Keyboard(_directInput);
_keyboard.Properties.BufferSize = 256;
_keyboard.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
_mouse = new Mouse(_directInput);
_mouse.Properties.AxisMode = DeviceAxisMode.Relative;
_mouse.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
var devices = _directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices);
if (devices.Count > 0)
{
_joystick = new Joystick(_directInput, devices[0].InstanceGuid);
_joystick.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
}
}
示例13: FormKey
public FormKey(SlimDX.DirectInput.DeviceType type, string deviceGuid, string keyName)
{
this.deviceType = type;
InitializeComponent();
DirectInput di = new DirectInput();
switch (type)
{
case SlimDX.DirectInput.DeviceType.Keyboard:
{
keyboard = new Keyboard(di);
keyboard.SetCooperativeLevel(this.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
break;
}
case SlimDX.DirectInput.DeviceType.Joystick:
{
joystick = new Joystick(di, Guid.Parse(deviceGuid));
joystick.SetCooperativeLevel(this.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
break;
}
case SlimDX.DirectInput.DeviceType.Other:
{
switch (deviceGuid)
{
case "x-controller-1": x_controller = new Controller(UserIndex.One); break;
case "x-controller-2": x_controller = new Controller(UserIndex.Two); break;
case "x-controller-3": x_controller = new Controller(UserIndex.Three); break;
case "x-controller-4": x_controller = new Controller(UserIndex.Four); break;
}
break;
}
}
timer_hold.Start();
label1.Text = string.Format(Program.ResourceManager.GetString("Text_PressAKeyFor") + " [{0}]", keyName);
stopTimer = 10;
label_cancel.Text = string.Format(Program.ResourceManager.GetString("Status_CancelIn") + " {0} " +
Program.ResourceManager.GetString("Status_Seconds"), stopTimer);
timer2.Start();
this.Select();
}
示例14: InputManager
public InputManager(IntPtr handle)
{
_devices = new List<InputDevice>();
var di = new DirectInput();
foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly))
{
if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard)
{
var keyboard = new Keyboard(di);
keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
_devices.Add(new InputDevice(keyboard));
}
else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick)
{
var joystick = new Joystick(di, device.InstanceGuid);
joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
_devices.Add(new InputDevice(joystick));
}
}
}
示例15: InitializeDevices
private void InitializeDevices()
{
var handle = WrenCore.WindowHandle;
_joysticks = new List<Joystick>();
DirectInput di = new DirectInput();
foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly))
{
if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard)
{
Keyboard keyboard = new Keyboard(di);
keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
_keyboard = keyboard;
}
else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick)
{
Joystick joystick = new Joystick(di, device.InstanceGuid);
joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
_joysticks.Add(joystick);
}
}
}