資源簡介
用C#寫的游戲手柄的訪問程序,并封裝成windows 消息,訪問非常方便。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Runtime.InteropServices;
namespace?JoyKeys
{
????public?partial?class?Form1?:?Form
????{
????????private?Core.Joystick?joystick;
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????protected?override?void?onload(EventArgs?e)
????????{
????????????base.onload(e);
????????????joystick?=?new?JoyKeys.Core.Joystick();
????????????joystick.Click?+=?new?EventHandler(joystick_Click);
????????????joystick.Register(base.Handle?Core.API.JOYSTICKID1);
????????????joystick.Register(base.Handle?Core.API.JOYSTICKID2);
????????}
????????protected?override?void?OnClosing(CancelEventArgs?e)
????????{
????????????joystick.UnRegister(Core.API.JOYSTICKID1);
????????????joystick.UnRegister(Core.API.JOYSTICKID2);
????????????base.OnClosing(e);
????????}
????????void?joystick_Click(object?sender?JoyKeys.Core.JoystickEventArgs?e)
????????{
???????????//?Core.API.JOYINFO?joy2?=?new?JoyKeys.Core.API.JOYINFO();
????????????if?(e.JoystickId?==?Core.API.JOYSTICKID1)
????????????{
????????????????this.Text?=?“1號手柄“;
????????????}
????????????else?if?(e.JoystickId?==?Core.API.JOYSTICKID2)
????????????{
????????????????this.Text?=?“2號手柄“;
????????????}
????????????int?x?=?1;
????????????int?y?=?1;
????????????string?str?=?““;
????????????this.Text?=?““?+?e.Move.X?+?“??“?+?e.Move.Y;
????????????if?((e.Buttons?&?JoyKeys.Core.JoystickButtons.UP)?==?JoyKeys.Core.JoystickButtons.UP)?y--;
????????????if?((e.Buttons?&?JoyKeys.Core.JoystickButtons.Down)?==?JoyKeys.Core.JoystickButtons.Down)?y++;
????????????if?((e.Buttons?&?JoyKeys.Core.JoystickButtons.Left)?==?JoyKeys.Core.JoystickButtons.Left)?x--;
????????????if?((e.Buttons?&?JoyKeys.Core.JoystickButtons.Right)?==?JoyKeys.Core.JoystickButtons.Right)?x++;
????????????if?(x?==?0?&&?y?==?0)?this.label1.TextAlign?=?ContentAlignment.TopLeft;
????????????if?(x?==?1?&&?y?==?0)?this.label1.TextAlign?=?ContentAlignment.TopCenter;
????????????if?(x?==?2?&&?y?==?0)?this.label1.TextAlign?=?ContentAlignment.TopRight;
????????????if?(x?==?0?&&?y?==?1)?this.label1.TextAlign?=?ContentAlignment.MiddleLeft;
????????????if?(x?==?1?&&?y?==?1)?this.label1.TextAlign?=?ContentAlignment.MiddleCenter;
????????????if?(x?==?2?&&?y?==?1)?this.label1.TextAlign?=?ContentAlignment.MiddleRight;
????????????if?(x?==?0?&&?y?==?2)?this.label1.TextAlign?=?ContentAlignment.BottomLeft;
????????????if?(x?==?1?&&?y?==?2)?this.label1.TextAlign?=?ContentAlignment.BottomCenter;
????????????if?(x?==?2?&&?y?==?2)?this.label1.TextAlign?=?ContentAlignment.BottomRight;
????????????this.label1.Text?=?“+“;
????????????this.label2.BackColor?=?((e.Buttons?&?JoyKeys.Core.JoystickButtons.B1)?==?JoyKeys.Core.JoystickButtons.B1)???Color.Red?:?SystemColors.Control;
??
評論
共有 條評論