DInput und Button....

WorldRacer

Erfahrenes Mitglied
Hallo,

wollte einen Button programmieren der mir ermittelt welcher Joystick Knopf gedrückt wird, sobald einer gedrückt wird. So wie in den Spielen halt, wenn man z.B. definiert auf welcher Taste die Hupe liegt.

Sieht bis jetzt so aus:

Code:
// Find all the GameControl devices that are attached.
	DeviceList^ conList = Manager::GetDevices(DeviceClass::GameControl,  EnumDevicesFlags::AttachedOnly);
				 
// check that we have at least one device.
	if(conList->Count > 0){
			conList->MoveNext();
			DeviceInstance^ devInst = (DeviceInstance)conList->Current;
			Device^ joy =  gcnew Device(devInst->InstanceGuid);
			joy->SetCooperativeLevel(this, CooperativeLevelFlags::Background | CooperativeLevelFlags::NonExclusive);
			joy->SetDataFormat(DeviceDataFormat::Joystick); 
		// Finally, acquire the device.
			joy->Acquire();
			DeviceCaps cps = joy->Caps;
			
		// Name of JoyStick
			MessageBox::Show("Chosen Device: " + joy->DeviceInformation.ProductName);
		// number of Axes
			MessageBox::Show("Joystick Axis: " + cps.NumberAxes);
		// number of Buttons
			MessageBox::Show("Joystick Buttons: " + cps.NumberButtons);
		// number of PoV hats
		 	MessageBox::Show("Joystick PoV hats: " + cps.NumberPointOfViews);
						
		try
		{
				 joy->Poll();
		         // update the joystick state field
			  	JoystickState state = joy->CurrentJoystickState;
						 
			 // cli::array<bool>^ buttons = gcnew array< bool>(joy->Caps.NumberButtons);
				 bool pressed = false;
				 while(!pressed){
				 	for(int i = 0; i < joy->Caps.NumberButtons; i++){
						state = joy->CurrentJoystickState;
	                			if(state.GetButtons()[i] >= 128){
							pressed = true;
							MessageBox::Show("Blubb");
						}
								    
				 	}
						     
				}

						 
			} catch (Exception^ err)  {
				 MessageBox::Show(err->Message);
			 }
					 

		 }

Aber sobald er in die while-Schleife geht ist Ende - Endlosschleife :rolleyes:
Ich denke es ist die Zeile:

Code:
 if(state.GetButtons()[i] >= 128){

^^Aber in nem anderen Fall geht die Zeile ohne Probleme...
da heissts nämlich:

bool buttonA = state.GetButtons()[0] >= 128;

und dann kann ich halt if(buttonA){ .... } blubb blah blah machen....

Bitte helft mir.

Danke im Vorraus!

WR
 
Zuletzt bearbeitet:
Mein Gott, dass ihr da net drauf kommt...

Ich hab nun die Lösung selbst gefunden...
in der while-Schleife zusätzlich noch joy-Poll(); ausführen und schon gehts....
 
Zurück