![]() |
|
joystic kontrolu - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: Genel Programlama (https://www.delphican.com/forumdisplay.php?fid=6) +--- Konu Başlığı: joystic kontrolu (/showthread.php?tid=7382) |
joystic kontrolu - sadikacar60 - 12-08-2023 arkadaslar usb direksiyon seti var bilgisayarda yaris oyunu icin bir oyun makinasinda revizyon yapmak istiyorum. usb direksiyon portunu program ile bloke edip geri acabilirmiyiz. bu mumkunmu. aslinda fiziksel olarak kontrol edebilirim usb data kablosunun Tx ucunu roleden gecirip joystick in kontrolunu alabilirim ama program ile yapmak istiyorum. fiziksel yaptigimizda her seferinde yeni donanim bulundu seklinde donanim kuruluyor ben bunu istemiyorum bilgisayar joystic i surekli gorsun ama kontrolu yazilimla benim elimden olsun. derdimi tam olarak anlatabildim insallah. saygilarimla joystic kontrolu - vedat35 - 13-08-2023 https://superuser.com/questions/502046/how-to-disable-and-enable-a-usb-port-via-command-prompt Download utility devcon from Microsoft. Then, use it as follows: List all known USB devices: devcon find USB* Disable USB device: devcon disable "USB\VID_xxxx&PID_yyyy" Enable USB device: devcon enable "USB\VID_xxxx&PID_yyyy" ilgili exe yi gizli window ile shellexecute ile çalıştırabilirsiniz. alternatif; https://www.nirsoft.net/articles/disable_enable_usb_device_command_line.html usb donanımları almak; https://blogs.embarcadero.com/quickly-enumerate-through-usb-devices-with-code-on-windows/ usb hub u disable etmek; https://groups.google.com/g/comp.lang.pascal.delphi.misc/c/k97mL8TgMZ8/m/WbLdcBdLc2sJ?pli=1 https://github.com/RRUZ/delphi-wmi-class-generator/blob/master/root_CIMV2/uWin32_USBHub.pas buradaki, SetPowerState(const PowerState : Word;const Time : TDateTime): Integer; test edilebilinir. denenebilir? https://www.tweakandtrick.com/2010/07/disable-access-to-usb-ports-in-your-pc.html https://www.partitionwizard.com/partitionmagic/disable-usb-ports-win11.html https://allusefulinfo.com/4-ways-to-disable-or-enable-usb-ports-in-your-windows-pc/ bu reg anahtarlarının etkisini test etmek gerekir çalışıyorsa, delphi kısmı basittir. denenebilinir. uses
Windows, SysUtils;
const
GUID_DEVINTERFACE_USB_DEVICE: TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}';
DIGCF_PRESENT = $00000002;
SPDRP_DEVICEDESC = $00000000;
CR_SUCCESS = $00000000;
CM_DEVCAP_SURPRISEREMOVALOK = $00000004;
DICS_FLAG_GLOBAL = $00000001;
DIREG_DEV = $00000001;
function SetupDiGetClassDevsA(
ClassGuid: PGUID;
Enumerator: PAnsiChar;
hwndParent: HWND;
Flags: DWORD
): THandle; stdcall; external 'setupapi.dll' name 'SetupDiGetClassDevsA';
function SetupDiEnumDeviceInfo(
DeviceInfoSet: THandle;
MemberIndex: DWORD;
DeviceInfoData: PSPDevInfoData
): LongBool; stdcall; external 'setupapi.dll' name 'SetupDiEnumDeviceInfo';
function SetupDiDestroyDeviceInfoList(
DeviceInfoSet: THandle
): LongBool; stdcall; external 'setupapi.dll' name 'SetupDiDestroyDeviceInfoList';
function SetupDiGetDeviceRegistryPropertyA(
DeviceInfoSet: THandle;
DeviceInfoData: PSPDevInfoData;
Property_: DWORD;
PropertyRegDataType: PDWORD;
PropertyBuffer: PByte;
PropertyBufferSize: DWORD;
RequiredSize: PDWORD
): LongBool; stdcall; external 'setupapi.dll' name 'SetupDiGetDeviceRegistryPropertyA';
function CM_Get_Device_IDA(
DevInst: DWORD;
Buffer: PAnsiChar;
BufferLen: DWORD;
Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Get_Device_IDA';
function CM_Locate_DevNodeA(
DevInst: PDWORD;
DevID: PAnsiChar;
Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Locate_DevNodeA';
function CM_Get_DevNode_Status(
Status: PDWORD;
ProblemNumber: PDWORD;
DevInst: DWORD;
Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Get_DevNode_Status';
function CM_Get_DevNode_Registry_PropertyA(
DevInst: DWORD;
Property_: DWORD;
RegDataType: PDWORD;
Buffer: PVOID;
BufferSize: PDWORD;
Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Get_DevNode_Registry_PropertyA';
function CM_Set_DevNode_Registry_PropertyA(
DevInst: DWORD;
Property_: DWORD;
Buffer: Pointer;
BufferSize: DWORD;
Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Set_DevNode_Registry_PropertyA';
function CM_Request_Device_EjectA(
DevInst: DWORD;
VetoType: PVetoType;
VetoName: PAnsiChar;
VetoNameSize: DWORD;
Flags: DWORD
): Longint; stdcall; external 'cfgmgr32.dll' name 'CM_Request_Device_EjectA';
type
SP_DEVINFO_DATA = packed record
cbSize: DWORD;
ClassGuid: TGUID;
DevInst: DWORD;
Reserved: ULONG_PTR;
end;
PSPDevInfoData = ^SP_DEVINFO_DATA;
VetoType = packed record
case Integer of
0: (VetoType: DWORD);
1: (VetoDriver: array [0..19] of AnsiChar);
2: (VetoName: array [0..259] of AnsiChar);
end;
PVetoType = ^VetoType;
procedure EnableUSBDevice(DeviceInstanceID: AnsiString);
var
hDevInfo: THandle;
DeviceInfoData: SP_DEVINFO_DATA;
DevInst: DWORD;
BufferSize: DWORD;
ProblemNumber, Status: DWORD;
Veto: VetoType;
begin
hDevInfo := SetupDiGetClassDevsA(@GUID_DEVINTERFACE_USB_DEVICE, nil, 0, DIGCF_PRESENT);
if hDevInfo <> INVALID_HANDLE_VALUE then
try
DeviceInfoData.cbSize := SizeOf(DeviceInfoData);
DevInst := 0;
while SetupDiEnumDeviceInfo(hDevInfo, DevInst, @DeviceInfoData) do
begin
BufferSize := 0;
if CM_Get_Device_IDA(DeviceInfoData.DevInst, nil, 0, 0) = CR_SUCCESS then
begin
SetLength(DeviceInstanceID, BufferSize - 1);
if CM_Get_Device_IDA(DeviceInfoData.DevInst, PAnsiChar(DeviceInstanceID), BufferSize, 0) = CR_SUCCESS then
Break;
end;
Inc(DevInst);
end;
if DevInst <> MAXDWORD then
begin
Status := CM_Get_DevNode_Status(@Status, @ProblemNumber, DeviceInfoData.DevInst, 0);
if (Status and DN_HAS_PROBLEM) = 0 then
begin
if (Status and DN_DISABLEABLE) <> 0 then
begin
Status := CM_Set_DevNode_Registry_PropertyA(
DeviceInfoData.DevInst,
CM_DEVCAP_SURPRISEREMOVALOK,
@Status,
SizeOf(Status),
DICS_FLAG_GLOBAL
);
if Status = CR_SUCCESS then
begin
Status := CM_Request_Device_EjectA(DeviceInfoData.DevInst, @Veto, nil, 0, 0);
if Status = CR_SUCCESS then
Writeln('USB device has been enabled.');
end;
end
else
Writeln('USB device is not disableable.');
end
else
Writeln('USB device has a problem and cannot be enabled.');
end
else
Writeln('USB device not found.');
finally
SetupDiDestroyDeviceInfoList(hDevInfo);
end
else
Writeln('Error getting device information.');
end;
begin
try
EnableUSBDevice(''); // Provide the appropriate DeviceInstanceID
except
on E: Exception do
Writeln('An error occurred: ', E.Message);
end;
end.
uses
Windows, SysUtils;
// ... Gerekli Windows API fonksiyonlarını ve türleri burada tanımlayın ...
procedure EnableUSBDevice(DeviceInstanceID: AnsiString);
begin
// ... Yukarıdaki örnek kodu buraya ekleyin ...
end;
procedure TForm1.EnableUSBButtonClick(Sender: TObject);
var
DeviceInstanceID: AnsiString;
begin
// Belirli bir USB cihazının DeviceInstanceID'sini buraya atayın
DeviceInstanceID := '...';
try
EnableUSBDevice(DeviceInstanceID);
ShowMessage('USB cihazı etkinleştirildi.');
except
on E: Exception do
ShowMessage('Hata oluştu: ' + E.Message);
end;
end;
procedure TForm1.DisableUSBButtonClick(Sender: TObject);
var
DeviceInstanceID: AnsiString;
begin
// Belirli bir USB cihazının DeviceInstanceID'sini buraya atayın
DeviceInstanceID := '...';
try
DisableUSBDevice(DeviceInstanceID);
ShowMessage('USB cihazı devre dışı bırakıldı.');
except
on E: Exception do
ShowMessage('Hata oluştu: ' + E.Message);
end;
end;
end.
joystic kontrolu - sadikacar60 - 13-08-2023 cok tesekkurler hocam donanim kismini halleder halettemez butun yontemleri deniyecegim. saygilar |