本文整理汇总了C#中Device.Acquire方法的典型用法代码示例。如果您正苦于以下问题:C# Device.Acquire方法的具体用法?C# Device.Acquire怎么用?C# Device.Acquire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.Acquire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInputDevices
protected void CreateInputDevices(Control target)
{
// create keyboard device.
keyboard = new Device(SystemGuid.Keyboard);
if (keyboard == null)
{
throw new Exception("No keyboard found.");
}
// create mouse device.
mouse = new Device(SystemGuid.Mouse);
if (mouse == null)
{
throw new Exception("No mouse found.");
}
// set cooperative level.
keyboard.SetCooperativeLevel(target, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
mouse.SetCooperativeLevel(target, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
// Acquire devices for capturing.
keyboard.Acquire();
mouse.Acquire();
}
示例2: Load
/// <summary>
/// Plugin entry point
/// </summary>
public override void Load()
{
drawArgs = ParentApplication.WorldWindow.DrawArgs;
DeviceList dl = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
dl.MoveNext();
if(dl.Current==null)
{
throw new ApplicationException("No joystick detected. Please check your connections and verify your device appears in Control panel -> Game Controllers.");
}
DeviceInstance di = (DeviceInstance) dl.Current;
joystick = new Device( di.InstanceGuid );
joystick.SetDataFormat(DeviceDataFormat.Joystick);
joystick.SetCooperativeLevel(ParentApplication,
CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
foreach(DeviceObjectInstance d in joystick.Objects)
{
// For axes that are returned, set the DIPROP_RANGE property for the
// enumerated axis in order to scale min/max values.
if((d.ObjectId & (int)DeviceObjectTypeFlags.Axis)!=0)
{
// Set the AxisRange for the axis.
joystick.Properties.SetRange(ParameterHow.ById, d.ObjectId, new InputRange(-AxisRange, AxisRange));
joystick.Properties.SetDeadZone(ParameterHow.ById, d.ObjectId, 1000); // 10%
}
}
joystick.Acquire();
// Start a new thread to poll the joystick
// TODO: The Device supports events, use them
joyThread = new Thread( new ThreadStart(JoystickLoop) );
joyThread.IsBackground = true;
joyThread.Start();
}
示例3: Init_Joystick_Device
public void Init_Joystick_Device()
{
//create joystick device.
foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly))
{
Joystick = new Device(di.InstanceGuid);
break;
}
if (Joystick != null)
{
joystickStatus = true;
}
//Set joystick axis ranges.
foreach (DeviceObjectInstance doi in Joystick.Objects)
{
if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
{
Joystick.Properties.SetRange(ParameterHow.ById, doi.ObjectId, new InputRange(1, 126));
}
}
//Set joystick axis mode absolute.
Joystick.Properties.AxisModeAbsolute = true;
//Joystick.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
//Acquire devices for capturing.
Joystick.Acquire();
}
示例4: Paddle
public Paddle()
{
foreach(DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly))
{
paddleDevice = new Device(di.InstanceGuid);
break;
}
if(paddleDevice != null)
{
try
{
paddleDevice.SetDataFormat(DeviceDataFormat.Joystick);
paddleDevice.Acquire();
}
catch(InputException)
{
}
}
pollTimer = new System.Timers.Timer(1);
pollTimer.Enabled = false;
pollTimer.Elapsed += new System.Timers.ElapsedEventHandler(pollTimer_Elapsed);
}
示例5: InitDevices
//Function of initialize device
public static void InitDevices()
{
//create joystick device.
foreach (DeviceInstance di in Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
//Throw exception if joystick not found.
}
//Set joystick axis ranges.
else {
foreach (DeviceObjectInstance doi in joystick.Objects)
{
if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
{
joystick.Properties.SetRange(
ParameterHow.ById,
doi.ObjectId,
new InputRange(-5000, 5000));
}
}
joystick.Properties.AxisModeAbsolute = true;
joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
//Acquire devices for capturing.
joystick.Acquire();
state = joystick.CurrentJoystickState;
}
}
示例6: SetupJoystick
private void SetupJoystick()
{
DeviceList list = Manager.GetDevices(Microsoft.DirectX.DirectInput.DeviceType.Joystick, EnumDevicesFlags.AttachedOnly);
System.Diagnostics.Debug.WriteLine(String.Format("Joystick list count: {0}", list.Count));
if (list.Count > 0)
{
while (list.MoveNext())
{
// Move to the first device
DeviceInstance deviceInstance = (DeviceInstance)list.Current;
try
{
// create a device from this controller.
Device = new Device(deviceInstance.InstanceGuid);
System.Diagnostics.Debug.WriteLine(String.Format("Device: {0} / {1}", Device.DeviceInformation.InstanceName, Device.DeviceInformation.ProductName));
Device.SetCooperativeLevel(Game.Window.Handle, CooperativeLevelFlags.Background | CooperativeLevelFlags.Exclusive);
// Tell DirectX that this is a Joystick.
Device.SetDataFormat(DeviceDataFormat.Joystick);
// Finally, acquire the device.
Device.Acquire();
System.Diagnostics.Debug.WriteLine(String.Format("Device acquired"));
break;
}
catch
{
Device = null;
System.Diagnostics.Debug.WriteLine(String.Format("Device acquire or data format setup failed"));
}
}
}
}
示例7: MouseInput
public MouseInput(Control parent)
{
// Create our mouse device
device = new Device(SystemGuid.Mouse);
device.SetCooperativeLevel(parent, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
device.Properties.AxisModeAbsolute = false;
device.Acquire();
}
示例8: KeyboardDevice
/// <summary>
/// Initializes a new instance of KeyboardDevice.
/// </summary>
public KeyboardDevice( Form form )
{
keyboard = new Device( SystemGuid.Keyboard );
keyboard.SetCooperativeLevel( form, CooperativeLevelFlags.Background |
CooperativeLevelFlags.NonExclusive );
keyboard.Acquire();
}
示例9: SlimDXKeyboard
/// <summary>
/// Initializes a new instance of the <see cref="SlimDXKeyboard"/> class.
/// </summary>
/// <param name="control">The control.</param>
public SlimDXKeyboard(Control control)
{
var directInput = DirectInput.FromPointer(control.Handle);
mKeyboard = new Device<KeyboardState>(directInput, SystemGuid.Keyboard);
mKeyboard.SetCooperativeLevel(control,
CooperativeLevel.Foreground | CooperativeLevel.Exclusive | CooperativeLevel.NoWinKey);
mKeyboard.Acquire();
}
示例10: MafiaInput
public MafiaInput(Form form)
{
this.form = form;
device = new Device(SystemGuid.Keyboard);
device.Acquire();
prevLeft = prevUp = prevRight = prevDown = false;
prevEnter = prevSpace = false;
prevAlt = false;
prevEsc = false;
}
示例11: SlimDXMouse
/// <summary>
/// Initializes a new instance of the <see cref="SlimDXMouse"/> class.
/// </summary>
/// <param name="control">The control.</param>
public SlimDXMouse(Control control)
{
mAxesActions = new Dictionary<Axis, AxisAction>(3);
var directInput = DirectInput.FromPointer(control.Handle);
mMouse = new Device<MouseState>(directInput, SystemGuid.Mouse);
mMouse.SetCooperativeLevel(control,
CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
mMouse.Acquire();
}
示例12: gamePad
public gamePad(Guid gamepadInstanceGuid, bool autoPoll)
{
device = new Device(gamepadInstanceGuid);
device.SetDataFormat(DeviceDataFormat.Joystick);
if (autoPoll == true)//If autopoll is on then continuous poll the pad in a seperate thread and return the results every change
{
new Thread(new ThreadStart(PollPad)).Start();//Start polling gamepad for buttons
device.SetEventNotification(gamePadUpdate);
}
device.Acquire();
}
示例13: Init
public void Init(Control parent)
{
_keyboard = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
_keyboard.SetCooperativeLevel(parent, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
_keyboard.Acquire();
_mouse = new Device(SystemGuid.Mouse);
_mouse.SetCooperativeLevel(parent,
CooperativeLevelFlags.NonExclusive |
CooperativeLevelFlags.Background);
_mouse.Acquire();
}
示例14: DInputHook
public DInputHook(IntPtr hWnd)
{
this.hWnd = hWnd;
keyboard = new Device(SystemGuid.Keyboard);
keyboardUpdated = new AutoResetEvent(false);
keyboard.SetCooperativeLevel(hWnd, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
keyboard.SetEventNotification(keyboardUpdated);
appShutdown = new ManualResetEvent(false);
threadloop = new Thread(new ThreadStart(ThreadFunction));
keyboard.Acquire();
threadloop.Start();
}
示例15: Gamepad
public Gamepad(Window wnd) {
foreach (DeviceInstance instance in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)) {
_joystick = new Device(instance.InstanceGuid);
break;
}
if (_joystick == null) {
Tools.ShowMessage("No gamepad found!", MessageType.Error);
}
else {
var helper = new WindowInteropHelper(wnd);
_joystick.SetCooperativeLevel(helper.Handle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
_joystick.Properties.BufferSize = 0x80;
_joystick.Acquire();
IsValid = true;
}
}