|
Robert Marquardt
(Gast)
n/a Beiträge |
#11
Alter Mann ist doch kein D-Zug
![]() Ich musste noch ein bischen Feinschliff betreiben wie Kommentare. Man erstelle sich ein Delphi-Projekt und speichere als OfficeRocketMain.pas und OfficeRocket.dpr. Danach die untenstehende Source kopieren und in OfficeRocketMain.pas pasten. Das selbe fuer die Form. Dazu schaltet man mit Rechtsklick auf "View as Text" um.
Code:
object OfficeRocketForm: TOfficeRocketForm
Left = 501 Top = 124 BorderIcons = [biSystemMenu, biMinimize] BorderStyle = bsSingle Caption = 'OfficeRocket' ClientHeight = 171 ClientWidth = 173 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False Position = poScreenCenter PixelsPerInch = 96 TextHeight = 13 object UpBtn: TSpeedButton Tag = 2 Left = 72 Top = 32 Width = 23 Height = 22 AllowAllUp = True GroupIndex = 2 Enabled = False Glyph.Data = { 76010000424D7601000000000000760000002800000020000000100000000100 04000000000000010000120B0000120B00001000000000000000000000000000 800000800000008080008000000080008000808000007F7F7F00BFBFBF000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333000333 3333333333777F33333333333309033333333333337F7F333333333333090333 33333333337F7F33333333333309033333333333337F7F333333333333090333 33333333337F7F33333333333309033333333333FF7F7FFFF333333000090000 3333333777737777F333333099999990333333373F3333373333333309999903 333333337F33337F33333333099999033333333373F333733333333330999033 3333333337F337F3333333333099903333333333373F37333333333333090333 33333333337F7F33333333333309033333333333337373333333333333303333 333333333337F333333333333330333333333333333733333333} NumGlyphs = 2 OnClick = CommandClick end object LeftBtn: TSpeedButton Left = 40 Top = 64 Width = 23 Height = 22 AllowAllUp = True GroupIndex = 1 Enabled = False Glyph.Data = { 76010000424D7601000000000000760000002800000020000000100000000100 04000000000000010000120B0000120B00001000000000000000000000000000 800000800000008080008000000080008000808000007F7F7F00BFBFBF000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333 3333333333333333333333333333333333333333333333333333333333333333 3333333333333FF3333333333333003333333333333F77F33333333333009033 333333333F7737F333333333009990333333333F773337FFFFFF330099999000 00003F773333377777770099999999999990773FF33333FFFFF7330099999000 000033773FF33777777733330099903333333333773FF7F33333333333009033 33333333337737F3333333333333003333333333333377333333333333333333 3333333333333333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333} NumGlyphs = 2 OnClick = CommandClick end object RightBtn: TSpeedButton Tag = 1 Left = 104 Top = 64 Width = 23 Height = 22 AllowAllUp = True GroupIndex = 1 Enabled = False Glyph.Data = { 76010000424D7601000000000000760000002800000020000000100000000100 04000000000000010000120B0000120B00001000000000000000000000000000 800000800000008080008000000080008000808000007F7F7F00BFBFBF000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333 3333333333333333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333FF3333333333333003333 3333333333773FF3333333333309003333333333337F773FF333333333099900 33333FFFFF7F33773FF30000000999990033777777733333773F099999999999 99007FFFFFFF33333F7700000009999900337777777F333F7733333333099900 33333333337F3F77333333333309003333333333337F77333333333333003333 3333333333773333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333} NumGlyphs = 2 OnClick = CommandClick end object DownBtn: TSpeedButton Tag = 3 Left = 72 Top = 96 Width = 23 Height = 22 AllowAllUp = True GroupIndex = 2 Enabled = False Glyph.Data = { 76010000424D7601000000000000760000002800000020000000100000000100 04000000000000010000120B0000120B00001000000000000000000000000000 800000800000008080008000000080008000808000007F7F7F00BFBFBF000000 FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333303333 333333333337F33333333333333033333333333333373F333333333333090333 33333333337F7F33333333333309033333333333337373F33333333330999033 3333333337F337F33333333330999033333333333733373F3333333309999903 333333337F33337F33333333099999033333333373333373F333333099999990 33333337FFFF3FF7F33333300009000033333337777F77773333333333090333 33333333337F7F33333333333309033333333333337F7F333333333333090333 33333333337F7F33333333333309033333333333337F7F333333333333090333 33333333337F7F33333333333300033333333333337773333333} NumGlyphs = 2 OnClick = CommandClick end object ShootBtn: TSpeedButton Tag = 4 Left = 59 Top = 128 Width = 49 Height = 22 AllowAllUp = True Caption = 'Shoot' Enabled = False OnClick = ShootBtnClick end object HidCtl: TJvHidDeviceController OnDeviceChange = HidCtlDeviceChange Left = 136 Top = 8 end end
Delphi-Quellcode:
Ich kann natuerlich nicht garantieren das es funktioniert, daher bitte testen und Fehler beseitigen.
unit OfficeRocketMain;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, StdCtrls, JvHidControllerClass; type TRocketInitRec = packed record ReportID: Byte; Payload: array [0..7] of Byte; end; TRocketCommandRec = packed record ReportID: Byte; Payload: array [0..63] of Byte; end; TRocketCommand = (rcLeft, rcRight, rcUp, rcDown, rcFire); TRocketCommands = set of TRocketCommand; TOfficeRocketForm = class(TForm) UpBtn: TSpeedButton; LeftBtn: TSpeedButton; RightBtn: TSpeedButton; DownBtn: TSpeedButton; ShootBtn: TSpeedButton; HidCtl: TJvHidDeviceController; procedure CommandClick(Sender: TObject); procedure HidCtlDeviceChange(Sender: TObject); procedure ShootBtnClick(Sender: TObject); public // both devices are needed to access Rocket Launcher RocketCommand: TJvHidDevice; RocketInit: TJvHidDevice; Commands: TRocketCommands; procedure SendRocketCommands(Cmds: TRocketCommands); end; var OfficeRocketForm: TOfficeRocketForm; implementation {$R *.dfm} function CheckCommandDevice(HidDev: TJvHidDevice): Boolean; stdcall; begin Result := (HidDev.Attributes.VendorID = $1130) and (HidDev.Attributes.ProductID = $0202) and (HidDev.Caps.OutputReportByteLength = 65); end; function CheckInitDevice(HidDev: TJvHidDevice): Boolean; stdcall; begin Result := (HidDev.Attributes.VendorID = $1130) and (HidDev.Attributes.ProductID = $0202) and (HidDev.Caps.OutputReportByteLength = 9); end; procedure TOfficeRocketForm.HidCtlDeviceChange(Sender: TObject); var Found: Boolean; begin // give back devices no matter which plug or unplug caused the event HidCtl.CheckIn(RocketCommand); HidCtl.CheckIn(RocketInit); // try to get the two Rocket devices if HidCtl.CheckOutByCallback(RocketCommand, CheckCommandDevice) then HidCtl.CheckOutByCallback(RocketInit, CheckInitDevice); // enable/disable GUI Found := Assigned(RocketCommand) and Assigned(RocketInit); DownBtn.Enabled := Found; LeftBtn.Enabled := Found; RightBtn.Enabled := Found; ShootBtn.Enabled := Found; UpBtn.Enabled := Found; end; procedure TOfficeRocketForm.SendRocketCommands(Cmds: TRocketCommands); const // init data to write to RocketInit device Init1: TRocketInitRec = (ReportID: $00; Payload: ($55, $53, $42, $43, $00, $00, $04, $00)); Init2: TRocketInitRec = (ReportID: $00; Payload: ($55, $53, $42, $43, $00, $40, $02, $00)); // data template to write to RocketCommand device (causes stop if unmodified) CmdEmpty: TRocketCommandRec = (ReportID: $00; Payload: ($00, $00, $00, $00, $00, $00, $08, $08, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00)); var Written: DWORD; Init: TRocketInitRec; Command: TRocketCommandRec; I: TRocketCommand; begin // send both init commands Init := Init1; RocketInit.WriteFile(Init, SizeOf(Init), Written); Init := Init2; RocketInit.WriteFile(Init, SizeOf(Init), Written); // collect commands into command record Command := CmdEmpty; for I := Low(TRocketCommand) to High(TRocketCommand) do if I in Cmds then Command.Payload[Ord(I) + 1] := $01; // send commands RocketCommand.WriteFile(Command, SizeOf(Command), Written); end; procedure TOfficeRocketForm.CommandClick(Sender: TObject); begin with Sender as TSpeedButton do if Down then Commands := Commands + [TRocketCommand(Tag)] else Commands := Commands + [TRocketCommand(Tag)]; SendRocketCommands(Commands); end; procedure TOfficeRocketForm.ShootBtnClick(Sender: TObject); begin with Sender as TSpeedButton do begin Commands := Commands + [TRocketCommand(Tag)]; SendRocketCommands(Commands); Commands := Commands + [TRocketCommand(Tag)]; end; end; end. |
![]() |
Ansicht |
![]() |
![]() |
![]() |
ForumregelnEs ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.
BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus. Trackbacks are an
Pingbacks are an
Refbacks are aus
|
|
Nützliche Links |
Heutige Beiträge |
Sitemap |
Suchen |
Code-Library |
Wer ist online |
Alle Foren als gelesen markieren |
Gehe zu... |
LinkBack |
![]() |
![]() |