Code: |
If MousePos > TmpMousePos Then ' Positive Drehrichtung, da neuer Wert größer als alter Else ' Negative Drehrichtung, da neuer Wert kleiner als alter End If |
Code: |
' Ende des rechten Bildschirms fast erlangt If MousePos > 1000 Then MousePos = 500 End If ' Ende des linken Bildschirms fast erlangt If MousePos < 10 Then MousePos = 500 End If |
Code: |
private void listDevices_DoubleClick(object sender, System.EventArgs e)
{ DeviceItem di = (DeviceItem)listDevices.SelectedItem; _iow24 = new Device(di.DevGuid); MessageBox.Show(_iow24.DeviceInformation.ProductName); eventFire = new AutoResetEvent(false); _iow24.SetEventNotification(eventFire); _iow24.Acquire(); // create ButtonReadThread threadData = new Thread(new ThreadStart(this.ButtonReaderThread)); threadData.Start(); } |
Code: |
Thread threadData = null;
AutoResetEvent eventFire = null; delegate void UIDelegate(); private Device _iow24; private DeviceList _dl; bool EncoderA = false; bool EncoderB = false; bool EncoderAOld = false; bool EncoderBOld = false; bool EncoderChanged = false; bool EncoderButton = false; bool EncoderDirection = false; int EncoderPos = 0; public void ButtonReaderThread() { while(Created) { eventFire.WaitOne(-1, false); try { EncoderA = _iow24.CurrentJoystickState.GetButtons()[8] != 0; EncoderB = _iow24.CurrentJoystickState.GetButtons()[9] != 0; EncoderButton = _iow24.CurrentJoystickState.GetButtons()[10] != 0; EncoderChanged = (EncoderA != EncoderAOld) || (EncoderB != EncoderBOld); if (EncoderChanged) { if (EncoderA != EncoderAOld) { if (EncoderA) EncoderDirection = !EncoderB; else EncoderDirection = EncoderB; } if (EncoderB != EncoderBOld) { if (EncoderB) EncoderDirection = EncoderA; else EncoderDirection = !EncoderA; } if (EncoderDirection) EncoderPos++; else EncoderPos--; } EncoderAOld = EncoderA; EncoderBOld = EncoderB; } catch(InputException) { continue; } if (Created) this.BeginInvoke(new UIDelegate(UpdateUI)); } |