本文整理汇总了C#中Device.SetDataFormat方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetDataFormat方法的具体用法?C# Device.SetDataFormat怎么用?C# Device.SetDataFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Device
的用法示例。
在下文中一共展示了Device.SetDataFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: initiate
private void initiate()
{
DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly); //get a list of attached game controllers
if (gameControllerList.Count > 0) //if there is a game controller then enter
{
// Move to the first device
gameControllerList.MoveNext();
DeviceInstance deviceInstance = (DeviceInstance) //picks the first controller
gameControllerList.Current;
// create a device from this controller.
joystickDevice = new Device(deviceInstance.InstanceGuid);
joystickDevice.SetCooperativeLevel(this,CooperativeLevelFlags.Background |CooperativeLevelFlags.NonExclusive);
joystickDevice.SetDataFormat(DeviceDataFormat.Joystick);
// Finally, acquire the device.
joystickDevice.Acquire();
}
}
示例2: Input
public Input(Control parentWindow)
{
// detect all available devices
foreach (DeviceInstance di in Manager.GetDevices(DeviceClass.All, EnumDevicesFlags.AllDevices))
{
if (di.DeviceType == DeviceType.Keyboard)
{
Keyboard = new Device(di.InstanceGuid);
Keyboard.SetDataFormat(DeviceDataFormat.Keyboard);
Keyboard.SetCooperativeLevel(parentWindow, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
}
else if (di.DeviceType == DeviceType.Mouse)
{
Mouse = new Device(di.InstanceGuid);
Mouse.SetDataFormat(DeviceDataFormat.Mouse);
Mouse.SetCooperativeLevel(parentWindow, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
}
else if (di.DeviceType == DeviceType.Joystick)
{
Joystick = new Device(di.InstanceGuid);
Joystick.SetDataFormat(DeviceDataFormat.Joystick);
Joystick.SetCooperativeLevel(parentWindow, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
}
//else if (di.DeviceType == DeviceType.Gamepad)
//{
// Gamepad = new Device(di.InstanceGuid);
// // must manually specify a format when working with different gamepads...i think ;x
// DataFormat customFormat;
// Gamepad.SetDataFormat(customFormat);
// Gamepad.SetCooperativeLevel(parentWindow, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
//}
}
}
示例3: InputSystem
public InputSystem(IntPtr hwnd)
{
try
{
// create the keyboard and mouse(very non-exclusively)
keyboard = new Device(SystemGuid.Keyboard);
keyboard.SetCooperativeLevel(hwnd, CooperativeLevelFlags.Background |
CooperativeLevelFlags.NonExclusive);
mouse = new Device(SystemGuid.Mouse);
mouse.SetCooperativeLevel(hwnd, CooperativeLevelFlags.Background |
CooperativeLevelFlags.NonExclusive);
mouse.SetDataFormat(DeviceDataFormat.Mouse);
// attempt to acquire
Acquire();
// allocate space for device state
keyboardState = new State[KEYBOARD_END + 1];
mouseButtonState = new State[mouse.CurrentMouseState.GetMouseButtons().Length];
}
catch (InputException e)
{
Ymfas.Util.RecordException(e);
throw;
}
}
示例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: 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"));
}
}
}
}
示例6: 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();
}
示例7: InputClass
public InputClass(Control owner)
{
this.owner = owner;
localDevice = new Device(SystemGuid.Keyboard);
localDevice.SetDataFormat(DeviceDataFormat.Keyboard);
localDevice.SetCooperativeLevel(owner, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
}
示例8: xKeyboard
public xKeyboard(Control Owner)
{
keyboard = new Device(SystemGuid.Keyboard);
keyboard.SetDataFormat(DeviceDataFormat.Keyboard);
keyboard.SetCooperativeLevel(Owner,
CooperativeLevelFlags.Foreground |
CooperativeLevelFlags.NonExclusive |
CooperativeLevelFlags.NoWindowsKey);
//keyboard.Acquire();
}
示例9: 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();
}
示例10: _createDevice
/// <summary>
/// Creates the DIKeyboard device.
/// </summary>
protected override void _createDevice()
{
_device = new Device(SystemGuid.Keyboard);
_device.SetDataFormat(DeviceDataFormat.Keyboard);
_device.SetCooperativeLevel(
_window,
CooperativeLevelFlags.NonExclusive |
CooperativeLevelFlags.NoWindowsKey |
CooperativeLevelFlags.Foreground
);
}
示例11: InputToolBox
public InputToolBox(GraphicEngine GE)
{
GE_object = GE;
try
{
KeyBoardDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard);
KeyBoardDevice.SetDataFormat(DeviceDataFormat.Keyboard);
KeyBoardDevice.Acquire();
MouseDevice = new Device(SystemGuid.Mouse);
MouseDevice.SetDataFormat(DeviceDataFormat.Mouse);
MouseDevice.Acquire();
}
catch (DirectXException ex)
{
MessageBox.Show(ex.Message, ex.Source);
}
}
示例12: DirectInputGamePad
public DirectInputGamePad(Guid gamePadGuid)
{
Device = new Device(gamePadGuid);
Device.SetDataFormat(DeviceDataFormat.Joystick);
Device.Acquire();
}
示例13: AddJoystickDevices
private void AddJoystickDevices(IntPtr windowHandle)
{
DeviceList gameControllerList = Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly);
for (int i = 0; i < gameControllerList.Count; i++)
{
gameControllerList.MoveNext();
DeviceInstance deviceInstance = (DeviceInstance)gameControllerList.Current;
Device device = new Device(deviceInstance.InstanceGuid);
if (device.DeviceInformation.ProductGuid != new Guid("0306057e-0000-0000-0000-504944564944") && // Wiimotes are excluded
!CheckIfDirectInputDeviceExists(device))
{
device.SetCooperativeLevel(windowHandle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
device.SetDataFormat(DeviceDataFormat.Joystick);
device.Acquire();
JoystickInput input = new JoystickInput(device);
AddInputDevice(input);
input.InitCurrentlyInvokedInput();
InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
}
}
}
示例14: AddKeyboardDevices
private void AddKeyboardDevices(IntPtr windowHandle)
{
DeviceList keyboardControllerList = Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly);
for (int i = 0; i < keyboardControllerList.Count; i++)
{
keyboardControllerList.MoveNext();
DeviceInstance deviceInstance = (DeviceInstance)keyboardControllerList.Current;
Device device = new Device(deviceInstance.InstanceGuid);
if (!CheckIfDirectInputDeviceExists(device))
{
device.SetCooperativeLevel(windowHandle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
device.SetDataFormat(DeviceDataFormat.Keyboard);
device.Acquire();
KeyboardInput input = new KeyboardInput(device);
AddInputDevice(input);
input.InitCurrentlyInvokedInput();
InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
}
}
}
示例15: Init
public static void Init(System.Windows.Forms.Control targetControl)
{
if (_Mouse == null)
_Mouse = new Mouse();
if (_EmptyState == null)
_EmptyState = new Mouse();
_Device = new Device(SystemGuid.Mouse);
_Device.SetCooperativeLevel(targetControl, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.NonExclusive);
_Device.SetDataFormat(DeviceDataFormat.Mouse);
targetControl.MouseMove += new MouseEventHandler(targetControl_MouseMove);
try { _Device.Acquire(); }
catch (DirectXException e) { Console.WriteLine(e.Message); }
}