GVKun编程网logo

您如何从/ dev / input / mice读取鼠标按钮状态?(mfc获取当前鼠标位置)

19

在本文中,我们将带你了解您如何从/dev/input/mice读取鼠标按钮状态?在这篇文章中,我们将为您详细介绍您如何从/dev/input/mice读取鼠标按钮状态?的方方面面,并解答mfc获取当前

在本文中,我们将带你了解您如何从/ dev / input / mice读取鼠标按钮状态?在这篇文章中,我们将为您详细介绍您如何从/ dev / input / mice读取鼠标按钮状态?的方方面面,并解答mfc获取当前鼠标位置常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的12、API - 输入设备(API - Input Devices)、android.view.InputDevice的实例源码、c# – Microsoft语音识别setInputToDefaultAudioDevice抛出异常、c# – 如何从XNode读取数据

本文目录一览:

您如何从/ dev / input / mice读取鼠标按钮状态?(mfc获取当前鼠标位置)

您如何从/ dev / input / mice读取鼠标按钮状态?(mfc获取当前鼠标位置)

您如何从/ dev / input / mice读取鼠标按钮状态?我想检测按钮是否被按下。

答案1

小编典典

您可以打开设备并阅读。来自/ dev / input / mice的事件的长度为3个字节,需要进行一些解析。我认为现在首选的方法是改用/ dev /
input / event#。但是,这是一个使用/ dev / input / mice的小示例。

#include <stdio.h>#include <unistd.h>#include <fcntl.h>int main(int argc, char** argv){    int fd, bytes;    unsigned char data[3];    const char *pDevice = "/dev/input/mice";    // Open Mouse    fd = open(pDevice, O_RDWR);    if(fd == -1)    {        printf("ERROR Opening %s\n", pDevice);        return -1;    }    int left, middle, right;    signed char x, y;    while(1)    {        // Read Mouse             bytes = read(fd, data, sizeof(data));        if(bytes > 0)        {            left = data[0] & 0x1;            right = data[0] & 0x2;            middle = data[0] & 0x4;            x = data[1];            y = data[2];            printf("x=%d, y=%d, left=%d, middle=%d, right=%d\n", x, y, left, middle, right);        }       }    return 0; }

鼠标单击生成以下内容:

x=0, y=0, left=1, middle=0, right=0x=0, y=0, left=0, middle=0, right=0

和一个鼠标移动(请注意“相对”鼠标移动坐标):

x=1, y=1, left=0, middle=0, right=0

12、API - 输入设备(API - Input Devices)

12、API - 输入设备(API - Input Devices)

学习目录:树莓派学习之路-GPIO Zero

官网地址:https://gpiozero.readthedocs.io/en/stable/api_input.html

环境:UbuntuMeta-16.04

树莓派:3代B型

提供这些简单地日常使用的输入设备组件接口。 在使用代码之前,必须正确使用该组件。

注意:所有GPIO引脚编号均使用Broadcom(BCM)编号。 有关详细信息,请参阅“基本配方(2、基本方法(Basic Recipes))”页面。

12.1. Button(按钮)

 classgpiozero.Button(pin*pull_up=Truebounce_time=Nonehold_time=1hold_repeat=Falsepin_factory=None)[source]

 

android.view.InputDevice的实例源码

android.view.InputDevice的实例源码

项目:GitHub    文件:TerminalTextViewOverlay.java   
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        // Selection may be beginning. Sync the TextView with the buffer.
        refreshTextFromBuffer();
    }

    // Mouse input is treated differently:
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
            MotionEventCompat.getSource(event) == InputDevice.soURCE_MOUSE) {
        if (onMouseEvent(event,terminalView.bridge)) {
            return true;
        }
        terminalView.viewPager.setPagingEnabled(true);
    } else {
        if (terminalView.onTouchEvent(event)) {
            return true;
        }
    }

    return super.onTouchEvent(event);
}
项目:exciting-app    文件:AbsHListView.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.soURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (mTouchMode == TOUCH_MODE_REST) {
                final float hscroll = event
                        .getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (hscroll != 0) {
                    final int delta = (int) (hscroll * getHorizontalScrollFactor());
                    if (!trackMotionScroll(delta,delta)) {
                        return true;
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}
项目:buildAPKsSamples    文件:GameView.java   
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    mInputManager.onGenericMotionEvent(event);

    // Check that the event came from a joystick or gamepad since a generic
    // motion event Could be almost anything. API level 18 adds the useful
    // event.isFromSource() helper function.
    int eventSource = event.getSource();
    if ((((eventSource & InputDevice.soURCE_GAMEPAD) == InputDevice.soURCE_GAMEPAD) ||
            ((eventSource & InputDevice.soURCE_JOYSTICK) == InputDevice.soURCE_JOYSTICK))
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        int id = event.getdeviceid();
        if (-1 != id) {
            Ship curShip = getShipForId(id);
            if (curShip.onGenericMotionEvent(event)) {
                return true;
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
项目:buildAPKsSamples    文件:GameView.java   
private static float getCenteredAxis(MotionEvent event,InputDevice device,int axis,int historyPos) {
    final InputDevice.MotionRange range = device.getMotionRange(axis,event.getSource());
    if (range != null) {
        final float flat = range.getFlat();
        final float value = historyPos < 0 ? event.getAxisValue(axis)
                : event.getHistoricalAxisValue(axis,historyPos);

        // Ignore axis values that are within the 'flat' region of the
        // joystick axis center.
        // A joystick at rest does not always report an absolute position of
        // (0,0).
        if (Math.abs(value) > flat) {
            return value;
        }
    }
    return 0;
}
项目:GravityBox    文件:PieController.java   
public void handleMessage(Message m) {
    switch (m.what) {
        case MSG_INJECT_KEY:
            final long eventTime = SystemClock.uptimeMillis();
            final InputManager inputManager = (InputManager)
                    XposedHelpers.callStaticmethod(InputManager.class,"getInstance");

            int flags = KeyEvent.FLAG_FROM_SYstem;
            XposedHelpers.callMethod(inputManager,"injectInputEvent",new KeyEvent(eventTime - 50,eventTime - 50,KeyEvent.ACTION_DOWN,m.arg1,KeyCharacterMap.VIRTUAL_KEYBOARD,flags,InputDevice.soURCE_UNKNowN),0);
            XposedHelpers.callMethod(inputManager,eventTime - 25,KeyEvent.ACTION_UP,0);

            break;
    }
}
项目:GravityBox    文件:ModHwKeys.java   
public static void injectKey(final int keyCode) {
    Handler handler = (Handler) XposedHelpers.getobjectField(mPhoneWindowManager,"mHandler");
    if (handler == null) return;

    handler.post(new Runnable() {
        @Override
        public void run() {
            try {
                final long eventTime = SystemClock.uptimeMillis();
                final InputManager inputManager = (InputManager)
                        mContext.getSystemService(Context.INPUT_SERVICE);
                int flags = KeyEvent.FLAG_FROM_SYstem;
                XposedHelpers.callMethod(inputManager,keyCode,0);
                XposedHelpers.callMethod(inputManager,0);
            } catch (Throwable t) {
                XposedBridge.log(t);
            }
        }
    });
}
项目:XposednavigationBar    文件:PointerEventdispatcherHook.java   
public static void hook(ClassLoader loader) {
    final Class<?> CLASS_POINTER_EVENT_disPATCHER = XposedHelpers.findClass(POINTER_EVENT_disPATCHER_PATH,loader);
    XposedHelpers.findAndHookMethod(CLASS_POINTER_EVENT_disPATCHER,"onInputEvent",InputEvent.class,new XC_MethodHook() {
        @Override
        protected void afterHookedMethod(MethodHookParam param) throws Throwable {
            super.afterHookedMethod(param);
            try {
                if (param.args[0] instanceof MotionEvent) {
                    MotionEvent event = (MotionEvent) param.args[0];
                    //XpLog.i("input x "+event.getX());
                    //XpLog.i("input y "+event.getY());
                    if ((event.getSource() & InputDevice.soURCE_CLASS_POINTER) != 0) {
                        PhoneWindowManagerHook.gesturesListener.onPointerEvent(event);
                    }
                }
            } catch (Exception e) {
                XpLog.e(e);
            }
        }
    });
}
项目:aos-MediaLib    文件:CoverRoll3D.java   
@Override
public boolean onGenericMotionEvent(MotionEvent event) {

    if ((event.getSource() & InputDevice.soURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            if(DBG) Log.d(TAG,"onGenericMotionEvent ACTION_SCROLL vscroll="+vscroll);
            if (vscroll != 0) {
                final int index = mLayout.getFrontCoverIndex();
                int targetIndex;
                if (index+vscroll<0) {
                    targetIndex=0;
                } else if (index+vscroll >= mCovers.size()-1) {
                    targetIndex = mCovers.size()-1;
                } else {
                    targetIndex = (int)(index+vscroll+0.5);
                }
                float targetScroll = mLayout.getScrollingPositionToCenterThisCover(targetIndex);
                mAnimHandler.startScrollingAnimPosition(targetScroll,AnimHandler.SPEED_FAST);
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}
项目:NeoTerm    文件:Video.java   
public void processGenericEvent(final MotionEvent event)
{
    // Joysticks are supported since Honeycomb,but I don't care about it,because very few devices have it
    if( (event.getSource() & InputDevice.soURCE_CLASS_JOYSTICK) == InputDevice.soURCE_CLASS_JOYSTICK )
    {
        // event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys,on Nvidia Shield and some other joysticks
        DemogLSurfaceView.nativeGamepadAnalogJoystickInput(
            event.getAxisValue(MotionEvent.AXIS_X),event.getAxisValue(MotionEvent.AXIS_Y),event.getAxisValue(MotionEvent.AXIS_Z),event.getAxisValue(MotionEvent.AXIS_RZ),event.getAxisValue(MotionEvent.AXIS_LTRIGGER),event.getAxisValue(MotionEvent.AXIS_RTRIGGER),event.getAxisValue(MotionEvent.AXIS_HAT_X),event.getAxisValue(MotionEvent.AXIS_HAT_Y),processGamepaddeviceid(event.getDevice()) );
        return;
    }
    // Process mousewheel
    if( event.getAction() == MotionEvent.ACTION_SCROLL )
    {
        int scrollX = Math.round(event.getAxisValue(MotionEvent.AXIS_HSCROLL));
        int scrollY = Math.round(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
        DemogLSurfaceView.nativeMouseWheel(scrollX,scrollY);
        return;
    }
    super.processGenericEvent(event);
}
项目:NeoTerm    文件:Video.java   
@Override
public boolean onKeyDown(int keyCode,final KeyEvent event)
{
    if( keyCode == KeyEvent.KEYCODE_BACK )
    {
        if( (event.getSource() & InputDevice.soURCE_MOUSE) == InputDevice.soURCE_MOUSE )
        {
            // Stupid Samsung and stupid Acer remaps right mouse button to BACK key
            nativeMouseButtonspressed(2,1);
            return true;
        }
        else if( mClient.isKeyboardWithoutTextInputShown() )
        {
            return true;
        }
    }

    if( nativeKey( keyCode,1,event.getUnicodeChar(),DifferentTouchInput.processGamepaddeviceid(event.getDevice()) ) == 0 )
        return super.onKeyDown(keyCode,event);

    return true;
}
项目:NeoTerm    文件:Video.java   
@Override
public boolean onKeyUp(int keyCode,0);
            return true;
        }
        else if( mClient.isKeyboardWithoutTextInputShown() )
        {
            mClient.showScreenKeyboardWithoutTextInputField(0); // Hide keyboard
            return true;
        }
    }

    if( nativeKey( keyCode,DifferentTouchInput.processGamepaddeviceid(event.getDevice()) ) == 0 )
        return super.onKeyUp(keyCode,event);

    //if( keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU )
    //  DimsystemStatusBar.get().dim(mClient._videoLayout);

    return true;
}
项目:heyaLauncher    文件:StartUpControllerObserver.java   
/**
 * Function that returns if any controller is paired/plugged/turned on
 */
private boolean hasConnectedController(){

    /*Get a list of valid input ids and iterate through them*/
    for (int deviceid : InputDevice.getdeviceids()) {

        InputDevice currentDevice = InputDevice.getDevice(deviceid);

        /*Device ID of the controller*/
        String controllerName = currentDevice.getName().toLowerCase(Locale.ENGLISH);

        /*Check to see if a kNown controller is connected*/
        if (controllerName.contains("controller") ||
                controllerName.contains("conteroller") ||
                controllerName.contains("contoroller") ||
                controllerName.contains("pad") ||
                controllerName.contains("joystick") ||
                controllerName.contains("nintendo")) {
            //|| (this.hidDevicesOK && controllerName.equals("hid_device"))){
            return true;
        }
    }
    return false;
}
项目:EnhancedPUMA    文件:MyInteractionController.java   
/**
 * Send keys and blocks until the first specified accessibility event.
 *
 * Most key presses will cause some UI change to occur. If the device is busy,this will
 * block until the device begins to process the key press at which point the call returns
 * and normal wait for idle processing may begin. If no events are detected for the
 * timeout period specified,the call will return anyway with false.
 *
 * @param keyCode
 * @param MetaState
 * @param eventType
 * @param timeout
 * @return true if events is received,otherwise false.
 */
public boolean sendKeyAndWaitForEvent(final int keyCode,final int MetaState,final int eventType,long timeout) {
    Runnable command = new Runnable() {
        @Override
        public void run() {
            final long eventTime = SystemClock.uptimeMillis();
            KeyEvent downEvent = new KeyEvent(eventTime,eventTime,MetaState,InputDevice.soURCE_KEYBOARD);
            if (injectEventSync(downEvent)) {
                KeyEvent upEvent = new KeyEvent(eventTime,InputDevice.soURCE_KEYBOARD);
                injectEventSync(upEvent);
            }
        }
    };

    return runAndWaitForEvents(command,new WaitForAnyEventPredicate(eventType),timeout) != null;
}
项目:RefreshRecyclerView    文件:RefreshRecyclerView.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.soURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                if (mTouchMode == TOUCH_MODE_REST) {
                    final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (vscroll != 0 && !trackMotionScroll((int) vscroll)) {
                        return true;
                    }
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
项目:atmosphere-uiautomator-bridge    文件:MotionEventSender.java   
public MotionEventSender() {
    try {
        Method imInstanceMethod = InputManager.class.getDeclaredMethod("getInstance");
        imInstanceMethod.setAccessible(true);
        inputManager = (InputManager) imInstanceMethod.invoke(null);

        injectInputEventMethod = InputManager.class.getDeclaredMethod("injectInputEvent",android.view.InputEvent.class,int.class);

        int[] deviceids = InputDevice.getdeviceids();
        for (int inputdeviceid : deviceids) {
            InputDevice inputDevice = InputDevice.getDevice(inputdeviceid);
            int deviceSources = inputDevice.getSources();
            if ((deviceSources & InputDevice.soURCE_TOUCHSCREEN) == InputDevice.soURCE_TOUCHSCREEN) {
                DEVICE_ID = inputdeviceid;
                break;
            }
        }
    } catch (Exception e) {
        e.printstacktrace();
        exitFailure();
    }

}
项目:contrib-drivers    文件:ButtonInputDriver.java   
static InputDriver build(Button button,final int keyCode) {
    final InputDriver inputDriver = new InputDriver.Builder(InputDevice.soURCE_CLASS_BUTTON)
            .setName(DRIVER_NAME)
            .setVersion(DRIVER_VERSION)
            .setKeys(new int[]{keyCode})
            .build();
    button.setonButtonEventListener(new Button.OnButtonEventListener() {
        @Override
        public void onButtonEvent(Button b,boolean pressed) {
            int keyAction = pressed ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP;
            inputDriver.emit(new KeyEvent[]{
                    new KeyEvent(keyAction,keyCode)
            });
        }
    });
    return inputDriver;
}
项目:AndroidStudyDemo    文件:ZrcAbsListView.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if (Build.VERSION.SDK_INT >= 12) {
        if ((event.getSource() & InputDevice.soURCE_CLASS_POINTER) != 0) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                if (mTouchMode == TOUCH_MODE_REST) {
                    final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    if (vscroll != 0) {
                        final int delta = (int) (vscroll * getVerticalScrollFactor());
                        if (!trackMotionScroll(delta,delta)) {
                            return true;
                        }
                    }
                }
            }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
项目:MD360Player4Android    文件:MDAbsView.java   
@Override
public void onEyeHitIn(MDHitEvent hitEvent) {
    super.onEyeHitIn(hitEvent);

    MDHitPoint point = hitEvent.getHitPoint();
    if (point == null || mAttachedView == null) {
        return;
    }
    int action = mTouchStatus == TouchStatus.nop ? MotionEvent.ACTION_HOVER_ENTER : MotionEvent.ACTION_HOVER_MOVE;
    float x = mAttachedView.getLeft() + mAttachedView.getWidth() * point.getU();
    float y = mAttachedView.getTop() + mAttachedView.getHeight() * point.getV();

    MotionEvent motionEvent = MotionEvent.obtain(hitEvent.getTimestamp(),System.currentTimeMillis(),action,x,y,0);
    motionEvent.setSource(InputDevice.soURCE_CLASS_POINTER);
    mAttachedView.dispatchGenericMotionEvent(motionEvent);
    motionEvent.recycle();
    mTouchStatus = TouchStatus.DOWN;

    invalidate();
}
项目:kgb    文件:KeyboardSwitcher.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static void injectTap(int x,int y,UiAutomation uiAutomation,boolean sync) {
  long downTime = System.currentTimeMillis();
  MotionEvent eventDown = MotionEvent.obtain(downTime,downTime,MotionEvent.ACTION_DOWN,0);
  eventDown.setSource(InputDevice.soURCE_TOUCHSCREEN);
  Log.d(TAG,"Injecting " + eventDown);

  if (!uiAutomation.injectInputEvent(eventDown,sync)) {
    Log.d(TAG,"Injection Failed");
  }

  MotionEvent eventUp = MotionEvent.obtain(eventDown);
  eventUp.setAction(MotionEvent.ACTION_UP);

  Log.d(TAG,"Injecting " + eventUp);
  if (!uiAutomation.injectInputEvent(eventUp,"Injection Failed");
  }

  eventDown.recycle();
  eventUp.recycle();
}
项目:DroneControl    文件:RollingSpiderActivity.java   
@Override
public boolean onGenericMotionEvent(MotionEvent ev) {
    if ((ev.getSource() & InputDevice.soURCE_JOYSTICK) == InputDevice.soURCE_JOYSTICK && ev.getAction() == MotionEvent.ACTION_MOVE) {

        if (rollingSpiderDeviceController != null) {

            if (mAutopilotMode) {
                autopiloting(ev);
            } else {
                normalPiloting(ev);
            }

            if (mTrianglepressed) {
                doTrick(ev);
            }
        }
    }
    return true;
}
项目:vlc_android_win    文件:AndroidDevices.java   
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
public static float getCenteredAxis(MotionEvent event,int axis) {
    final InputDevice.MotionRange range =
            device.getMotionRange(axis,event.getSource());

    // A joystick at rest does not always report an absolute position of
    // (0,0). Use the getFlat() method to determine the range of values
    // bounding the joystick axis center.
    if (range != null) {
        final float flat = range.getFlat();
        final float value = event.getAxisValue(axis);

        // Ignore axis values that are within the 'flat' region of the
        // joystick axis center.
        if (Math.abs(value) > flat) {
            return value;
        }
    }
    return 0;
}
项目:stepik-android    文件:AndroidDevices.java   
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
public static float getCenteredAxis(MotionEvent event,0). Use the getFlat() method to determine the range of values
    // bounding the joystick axis center.
    if (range != null) {
        final float flat = range.getFlat();
        final float value = event.getAxisValue(axis);

        // Ignore axis values that are within the 'flat' region of the
        // joystick axis center.
        if (Math.abs(value) > flat) {
            return value;
        }
    }
    return 0;
}
项目:cordova-android-tv    文件:CordovaPluginGamepad.java   
@TargetApi(12)
private JSONObject createGamepadForInputDevice(InputDevice inputDevice)
        throws JSONException
{
    JSONObject gamepad = new JSONObject();
    JSONArray axes = new JSONArray();
    for (int i = 0; i < NUMBER_OF_AXES; i++)
    {
        axes.put(ZERO);
    }
    JSONArray buttons = new JSONArray();
    for (int i = 0; i < NUMBER_OF_BUTTONS; i++)
        buttons.put(ZERO);
    int deviceid = inputDevice.getId();
    long index = deviceidToIndex.containsKey(deviceid) ? deviceidToIndex
            .get(deviceid) : getFirstFreeIndex();
    deviceidToIndex.put(deviceid,index);
    gamepad.put(ID,inputDevice.getName());
    gamepad.put(INDEX,index);
    gamepad.put(CONNECTED,true);
    gamepad.put(TIME_STAMP,System.currentTimeMillis() - initialTimeMillis);
    gamepad.put(MAPPING,"standard");
    gamepad.put(AXES,axes);
    gamepad.put(BUTTONS,buttons);
    return gamepad;
}
项目:Crazy-wheel-godot-google-play    文件:GodotView.java   
@Override public boolean onKeyUp(int keyCode,KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            return super.onKeyUp(keyCode,event);
        };

        int source = event.getSource();
        if ((source & InputDevice.soURCE_JOYSTICK) != 0 || (source & InputDevice.soURCE_DPAD) != 0 || (source & InputDevice.soURCE_GAMEPAD) != 0) {

            int button = get_godot_button(keyCode);
            int device = event.getdeviceid();

            GodotLib.joybutton(device,button,false);
            return true;
        } else {

            GodotLib.key(keyCode,event.getUnicodeChar(0),false);
        };
        return super.onKeyUp(keyCode,event);
    }
项目:Crazy-wheel-godot-google-play    文件:GodotView.java   
public float axis_value(MotionEvent p_event,InputDevice p_device,int p_axis,int p_pos) {

        final InputDevice.MotionRange range = p_device.getMotionRange(p_axis,p_event.getSource());
        if (range == null)
            return 0;

        //Log.e(TAG,String.format("axis ranges %f,%f,%f",range.getRange(),range.getMin(),range.getMax()));

        final float flat = range.getFlat();
        final float value =
            p_pos < 0 ? p_event.getAxisValue(p_axis):
            p_event.getHistoricalAxisValue(p_axis,p_pos);

        final float absval = Math.abs(value);
        if (absval <= flat) {
            return 0;
        };

        final float ret = (value - range.getMin()) / range.getRange() * 2 - 1.0f;

        return ret;
    }
项目:Crazy-wheel-godot-google-play    文件:GodotView.java   
@Override public boolean onGenericMotionEvent(MotionEvent event) {

        if ((event.getSource() & InputDevice.soURCE_JOYSTICK) == InputDevice.soURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) {

            // Process all historical movement samples in the batch
            final int historySize = event.getHistorySize();

            // Process the movements starting from the
            // earliest historical position in the batch
            for (int i = 0; i < historySize; i++) {
                // Process the event at historical position i
                process_axis_state(event,i);
            }

            // Process the current movement sample in the batch (position -1)
            process_axis_state(event,-1);
            return true;


        };

        return super.onGenericMotionEvent(event);
    }
项目:VCL-Android    文件:AudioPlayerActivity.java   
public boolean dispatchGenericMotionEvent(MotionEvent event){
    //Check for a joystick event
    if ((event.getSource() & InputDevice.soURCE_JOYSTICK) !=
            InputDevice.soURCE_JOYSTICK ||
            event.getAction() != MotionEvent.ACTION_MOVE)
        return false;

    InputDevice inputDevice = event.getDevice();

    float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
    float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
    if (inputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f)
        return false;

    float x = AndroidDevices.getCenteredAxis(event,inputDevice,MotionEvent.AXIS_X);

    if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){
        if (Math.abs(x) > 0.3){
            seek(x > 0.0f ? 10000 : -10000);
            mLastMove = System.currentTimeMillis();
            return true;
        }
    }
    return true;
}
项目:VCL-Android    文件:AndroidDevices.java   
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
public static float getCenteredAxis(MotionEvent event,0). Use the getFlat() method to determine the range of values
    // bounding the joystick axis center.
    if (range != null) {
        final float flat = range.getFlat();
        final float value = event.getAxisValue(axis);

        // Ignore axis values that are within the 'flat' region of the
        // joystick axis center.
        if (Math.abs(value) > flat) {
            return value;
        }
    }
    return 0;
}
项目:nexus-gallery    文件:galleryActivity.java   
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    final boolean isTouchPad = (event.getSource()
            & InputDevice.soURCE_CLASS_POSITION) != 0;
    if (isTouchPad) {
        float maxX = event.getDevice().getMotionRange(MotionEvent.AXIS_X).getMax();
        float maxY = event.getDevice().getMotionRange(MotionEvent.AXIS_Y).getMax();
        View decor = getwindow().getDecorView();
        float scaleX = decor.getWidth() / maxX;
        float scaleY = decor.getHeight() / maxY;
        float x = event.getX() * scaleX;
        //x = decor.getWidth() - x; // invert x
        float y = event.getY() * scaleY;
        //y = decor.getHeight() - y; // invert y
        MotionEvent touchEvent = MotionEvent.obtain(event.getDownTime(),event.getEventTime(),event.getAction(),event.getMetaState());
        return dispatchTouchEvent(touchEvent);
    }
    return super.onGenericMotionEvent(event);
}
项目:knightsofalentejo    文件:GameActivity.java   
private List<Integer> getGameControllerIds() {
    List<Integer> gameControllerdeviceids = new ArrayList<>();

    int[] deviceids = InputDevice.getdeviceids();
    for (int deviceid : deviceids) {
        InputDevice dev = InputDevice.getDevice(deviceid);
        int sources = dev.getSources();

        if (((sources & InputDevice.soURCE_GAMEPAD) == InputDevice.soURCE_GAMEPAD)
                || ((sources & InputDevice.soURCE_JOYSTICK)
                == InputDevice.soURCE_JOYSTICK)) {

            if (!gameControllerdeviceids.contains(deviceid)) {
                gameControllerdeviceids.add(deviceid);
            }
        }
    }

    return gameControllerdeviceids;
}
项目:StockAdapterView    文件:AbsListView.java   
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.soURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL:
                if (mTouchMode == TOUCH_MODE_REST) {
                    final float vscroll
                            = MotionEventCompat.getAxisValue(event,MotionEventCompat.AXIS_VSCROLL);
                    if (vscroll != 0) {
                        final int delta = (int) (vscroll * ViewUtils.getVerticalScrollFactor(this));
                        if (!trackMotionScroll(delta,delta)) {
                            return true;
                        }
                    }
                }
                break;
        }
    }

    return super.onGenericMotionEvent(event);
}
项目:365browser    文件:GamepadDevice.java   
GamepadDevice(int index,InputDevice inputDevice) {
    mDeviceIndex = index;
    mdeviceid = inputDevice.getId();
    mDeviceName = inputDevice.getName();
    mTimestamp = SystemClock.uptimeMillis();
    // Get axis ids and initialize axes values.
    final List<MotionRange> ranges = inputDevice.getMotionRanges();
    mAxes = new int[ranges.size()];
    int i = 0;
    for (MotionRange range : ranges) {
        if ((range.getSource() & InputDevice.soURCE_CLASS_JOYSTICK) != 0) {
            int axis = range.getAxis();
            assert axis < MAX_RAW_AXIS_VALUES;
            mAxes[i++] = axis;
        }
    }
    mMappings = GamepadMappings.getMappings(inputDevice,mAxes);
}
项目:mc_backup    文件:AndroidGamepadManager.java   
public Gamepad(int serviceId,int deviceid) {
    id = serviceId;
    axes = new float[Axis.values().length];
    dpad = new boolean[4];
    triggers = new float[2];

    InputDevice device = InputDevice.getDevice(deviceid);
    if (device != null) {
        // LTRIGGER/RTRIGGER don't seem to be exposed on older
        // versions of Android.
        if (device.getMotionRange(MotionEvent.AXIS_LTRIGGER) != null && device.getMotionRange(MotionEvent.AXIS_RTRIGGER) != null) {
            triggerAxes = new int[]{MotionEvent.AXIS_LTRIGGER,MotionEvent.AXIS_RTRIGGER};
        } else if (device.getMotionRange(MotionEvent.AXIS_BRAKE) != null && device.getMotionRange(MotionEvent.AXIS_GAS) != null) {
            triggerAxes = new int[]{MotionEvent.AXIS_BRAKE,MotionEvent.AXIS_GAS};
        } else {
            triggerAxes = null;
        }
    }
}
项目:mc_backup    文件:AndroidGamepadManager.java   
private static void scanForGamepads() {
    int[] deviceids = InputDevice.getdeviceids();
    if (deviceids == null) {
        return;
    }
    for (int i=0; i < deviceids.length; i++) {
        InputDevice device = InputDevice.getDevice(deviceids[i]);
        if (device == null) {
            continue;
        }
        if ((device.getSources() & InputDevice.soURCE_GAMEPAD) != InputDevice.soURCE_GAMEPAD) {
            continue;
        }
        addGamepad(device);
    }
}
项目:mc_backup    文件:JavaPanZoomController.java   
/** This function MUST be called on the UI thread */
@Override
public boolean onKeyEvent(KeyEvent event) {
    if (Versions.preHCMR1) {
        return false;
    }

    if ((event.getSource() & InputDevice.soURCE_GAMEPAD) == InputDevice.soURCE_GAMEPAD
        && event.getAction() == KeyEvent.ACTION_DOWN) {

        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_ZOOM_IN:
            return animatedScale(0.2f);
        case KeyEvent.KEYCODE_ZOOM_OUT:
            return animatedScale(-0.2f);
        }
    }
    return false;
}
项目:mc_backup    文件:JavaPanZoomController.java   
/** This function MUST be called on the UI thread */
@Override
public boolean onMotionEvent(MotionEvent event) {
    if (Versions.preHCMR1) {
        return false;
    }

    switch (event.getSource() & InputDevice.soURCE_CLASS_MASK) {
    case InputDevice.soURCE_CLASS_POINTER:
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_SCROLL: return handlePointerScroll(event);
        }
        break;
    case InputDevice.soURCE_CLASS_JOYSTICK:
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_MOVE: return handleJoystickNav(event);
        }
        break;
    }
    return false;
}
项目:mc_backup    文件:GamepadUtils.java   
private static boolean areSonyXperiaGamepadKeysSwapped() {
    // The cross and circle buttons on Sony Xperia phones are swapped
    // in different regions
    // http://developer.sonymobile.com/2011/02/13/xperia-play-game-keys/
    final char DEFAULT_O_BUTTON_LABEL = 0x25CB;

    boolean swapped = false;
    int[] deviceids = InputDevice.getdeviceids();

    for (int i= 0; deviceids != null && i < deviceids.length; i++) {
        KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(deviceids[i]);
        if (keyCharacterMap != null && DEFAULT_O_BUTTON_LABEL ==
            keyCharacterMap.getdisplayLabel(KeyEvent.KEYCODE_DPAD_CENTER)) {
            swapped = true;
            break;
        }
    }
    return swapped;
}
项目:DeckView    文件:DeckViewTouchHandler.java   
/**
 * Handles generic motion events
 */
public boolean onGenericMotionEvent(MotionEvent ev) {
    if ((ev.getSource() & InputDevice.soURCE_CLASS_POINTER) ==
            InputDevice.soURCE_CLASS_POINTER) {
        int action = ev.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_SCROLL:
                // Find the front most task and scroll the next task to the front
                float vScroll = ev.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (vScroll > 0) {
                    if (mDeckView.ensureFocusedTask()) {
                        mDeckView.focusNextTask(true,false);
                    }
                } else {
                    if (mDeckView.ensureFocusedTask()) {
                        mDeckView.focusNextTask(false,false);
                    }
                }
                return true;
        }
    }
    return false;
}
项目:vlc-android    文件:AudioPlayerActivity.java   
public boolean dispatchGenericMotionEvent(MotionEvent event){
    //Check for a joystick event
    if ((event.getSource() & InputDevice.soURCE_JOYSTICK) !=
            InputDevice.soURCE_JOYSTICK ||
            event.getAction() != MotionEvent.ACTION_MOVE)
        return false;

    InputDevice inputDevice = event.getDevice();

    float dpadx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
    float dpady = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
    if (inputDevice == null || Math.abs(dpadx) == 1.0f || Math.abs(dpady) == 1.0f)
        return false;

    float x = AndroidDevices.getCenteredAxis(event,MotionEvent.AXIS_X);

    if (System.currentTimeMillis() - mLastMove > JOYSTICK_INPUT_DELAY){
        if (Math.abs(x) > 0.3){
            seek(x > 0.0f ? 10000 : -10000);
            mLastMove = System.currentTimeMillis();
            return true;
        }
    }
    return true;
}

c# – Microsoft语音识别setInputToDefaultAudioDevice抛出异常

c# – Microsoft语音识别setInputToDefaultAudioDevice抛出异常

你好,我在MS语音识别方面遇到了麻烦.

我的代码很简单.

static void init()
    {
        string enUsEngine = string.Empty;


        foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
        {
            Console.WriteLine(ri.Culture);
            if (ri.Culture.Name.Equals("en-US") == true)
            {
                enUsEngine = ri.Id;
            }
        }

        SpeechRecognitionEngine recogEngine = new SpeechRecognitionEngine(enUsEngine);

        Grammar grammar = new Grammar("grammar.xml");
        recogEngine.LoadGrammar(grammar);

        recogEngine.SpeechRecognized += recogEngine_SpeechRecognized;
        recogEngine.RecognizeCompleted += recogEngine_RecognizeCompleted;

        recogEngine.SetInputToDefaultAudioDevice();

        recogEngine.RecognizeAsync(RecognizeMode.Multiple);

    }

然后在调用中抛出InvalidOperationException

(system.invalidOperationException: Cannot find the requested data
item,such as a data key or value.)

SetInputToDefaultAudioDevice();方法

我下载了Msspeech sdk并安装了它(Microsoft.speech.dll).
还下载了语言包. (en-us,ko-kr)

还在控制面板中安装并启用了我的麦克风驱动程序.

请帮我.

我的操作系统是Windows 10是使用语音识别API的问题吗?

解决方法

@H_301_36@ 很可能你使用的是Microsoft.Speech.Recognition,你应该使用System.Speech.Recognition.

改变这个:

using Microsoft.Speech.Recognition;

对此:

using System.Speech.Recognition;

您可以保留其余代码.

瓦?那么这里有一些答案:
What is the difference between System.Speech.Recognition and Microsoft.Speech.Recognition?

简而言之,Microsoft.Speech.Recognition适用于服务器,可以在呼叫中心(用于自动化等)中使用低质量音频,这意味着它与所有音频输入设备不兼容.

相反,System.Speech.Recognition适用于桌面应用程序,它完全支持Windows上安装的默认录制设备.

c# – 如何从XNode读取数据

c# – 如何从XNode读取数据

如何从XNode读取数据.

这是我从另一个查询获得的XNode.

<claim kind="national" sequence="1">
  <country>UK</country>
  <number>66</number>
  <date>20080602</date>
</claim>
<claim kind="national" sequence="3">
  <country>TH</country>
  <number>61</number>
  <date>20090316</date>
</claim>

我想得到国家和日期的价值.

任何帮助将非常感激.
谢谢.

解决方法

尝试,

var list = from ele in XDocument.Load(@"c:\file.xml").Descendants("claim")
           select new
            {
              Country=(string)ele.Element("country"),Date=(string)ele.Element("date")
             };
 foreach (var t in list)
 {
    Console.WriteLine(t.Country + " "+ t.Date );
 }

编辑:

string country=(string)((XElement)xNodeObj).Element("country");

关于您如何从/ dev / input / mice读取鼠标按钮状态?mfc获取当前鼠标位置的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于12、API - 输入设备(API - Input Devices)、android.view.InputDevice的实例源码、c# – Microsoft语音识别setInputToDefaultAudioDevice抛出异常、c# – 如何从XNode读取数据等相关内容,可以在本站寻找。

本文标签: