void OnGUI () {
		if(gameObject.GetComponent<W7TouchManager>().isWinTouchDevice) {
			for (int n=0; n<id; n++) {
				ress = W7TouchManager.GetTouch(n);
				GUI.DrawTexture (new Rect (ress.Position.x-20, Screen.height-ress.Position.y-20, 40, 40), aTexture, ScaleMode.ScaleToFit);
			}
		} else {
			ismoving = (Mathf.Abs(Input.GetAxis("Mouse X"))+Mathf.Abs(Input.GetAxis("Mouse Y")) > 0) ? 10 : ismoving-1;
			if (Input.GetMouseButton(0) && ismoving > 0) {
				GUI.color = new Color(1f,1f,1f,(1f/10)*ismoving);
				GUI.DrawTexture (new Rect (mouseInput.x-15, Screen.height-mouseInput.y-15, 30, 30), aTexture, ScaleMode.ScaleToFit);
			}
		}
	}
    void Update() {
        if (isWinTouchDevice && hHook != 0) {
            // clean previous touches
            List<W7Touch> touchesToDelete = new List<W7Touch>();

            // remove duplicate touch ids (down + move, move + move, ...)
            Dictionary<uint, W7Touch> duplicateTouches = new Dictionary<uint, W7Touch>();
            foreach (W7Touch touch in touches) {
                if (duplicateTouches.ContainsKey(touch.Id)) {
                    touchesToDelete.Add(duplicateTouches[touch.Id]);
                    duplicateTouches[touch.Id] = touch;
                } else {
                    duplicateTouches.Add(touch.Id, touch);
                }
            }
            foreach (W7Touch touch in touchesToDelete) {
                touches.Remove(touch);
            }
            touchesToDelete.Clear();

            // remove ended touches
            foreach (W7Touch touch in touches) {
                if (touch.Phase == TouchPhase.Ended || touch.Phase == TouchPhase.Canceled) {
                    touchesToDelete.Add(touch);
                    touchIdMap.Remove(touch.Id);
                } else if (touch.Phase == TouchPhase.Began) {
                    touch.Phase = TouchPhase.Stationary;
                }
            }
            foreach (W7Touch touch in touchesToDelete) {
                touches.Remove(touch);
            }
            touchesToDelete.Clear();

            lock (rawTouchesQueue) {
                while (rawTouchesQueue.Count > 0) {
                    TOUCHINPUT[] rawTouches = rawTouchesQueue.Dequeue();
                    for (uint i = 0; i < rawTouches.Length; ++i) {
                        TOUCHINPUT rawTouch = rawTouches[i];
                        //Debug.Log(rawTouch.dwID + ": " + rawTouch.dwFlags + " at " + rawTouch.x + "," + rawTouch.y);

                        if (!touchIdMap.ContainsKey(rawTouch.dwID)) {
                            touchIdMap.Add(rawTouch.dwID, lastTouchId);
                            lastTouchId++;
                        }

                        W7Touch touch;
                        try {
                            touch = touches.Find(t => t.Id == touchIdMap[rawTouch.dwID]);
                        } catch {
                            touch = null;
                        }

                        Vector2 pos = new Vector2(rawTouch.x * 0.01f, rawTouch.y * 0.01f);
                        if (touch != null) {
                            if ((rawTouch.dwFlags & TOUCHEVENTF_DOWN) == TOUCHEVENTF_DOWN) {
                                // duplicate down event, ignore
                                continue;
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_MOVE) == TOUCHEVENTF_MOVE) {
                                if (touch.Phase == TouchPhase.Canceled || touch.Phase == TouchPhase.Ended) {
                                    // moving an ended touch? do nothing, which means resume movement
                                    touch.UpdateTouch(pos);
                                } else if (touch.Phase == TouchPhase.Began) {
                                    // preserve began phase but update position;
                                    touch.UpdateTouch(pos);
                                    touch.Phase = TouchPhase.Began;
                                } else {
                                    touch.UpdateTouch(pos);
                                }
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_UP) == TOUCHEVENTF_UP) {
                                touch.EndTouch();
                            }
                        } else {
                            touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                            touches.Add(touch);
                            if ((rawTouch.dwFlags & TOUCHEVENTF_DOWN) == TOUCHEVENTF_DOWN) {
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_MOVE) == TOUCHEVENTF_MOVE) {
                                // move without down? add a new movement touch
                                touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                touch.UpdateTouch(pos);
                                touches.Add(touch);
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_UP) == TOUCHEVENTF_UP) {
                                // up without down? add a new end touch
                                touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                touch.EndTouch();
                                touches.Add(touch);
                            }
                        }
                    }
                }
            }
            foreach (W7Touch touch in touches) {
                touch.Update();
                if (touch.Phase == TouchPhase.Canceled) {
                    var k = (from t in touchIdMap where t.Value == touch.Id select t.Key);
                    if (k.Count() > 0) {
                        touchIdMap.Remove(k.First());
                    }
                }
            }
        }
    }
    /// <summary>
    /// 入力デバイスにより分岐する
    /// </summary>
    private void InputDevice()
    {
        isTouch    = true;
        touchCount = 0;

        //for Win7Touch
        if (inputType == INPUT_TYPE.W7TOUCH)
        {
#if UNITY_STANDALONE_WIN
            //WindowsのときのみWin7Touchが必要
            touchCount = W7TouchManager.GetTouchCount();

            //1点目を入力として受付
            if (touchCount >= 1)
            {
                W7Touch w7t1  = W7TouchManager.GetTouch(0);
                Rect    wrect = Utils.WindowsUtil.GetApplicationWindowRect();              //not work in Editor.
                touchPosition = new Vector2(
                    (int)(((w7t1.Position.x / Screen.width) * Screen.currentResolution.width) - wrect.x),
                    Screen.height + (int)(((w7t1.Position.y / Screen.height) * Screen.currentResolution.height) - wrect.y));
                TouchPhase tphase = w7t1.Phase;

                if (tphase == TouchPhase.Began)
                {
                    //isPressed == Trueの状態でBeganがくることはありえないのだが来てしまうときがある
                    //その場合はMovedということにする
                    if (isPressed)
                    {
                        phase = INPUT_PHASE.Moved;
                    }
                    else
                    {
                        phase = INPUT_PHASE.Began;
                    }
                }
                else if (tphase == TouchPhase.Ended || tphase == TouchPhase.Canceled)
                {
                    //Win7Touchではここにはこないようです
                    phase = INPUT_PHASE.Ended;
                }
                else if (tphase == TouchPhase.Moved || tphase == TouchPhase.Stationary)
                {
                    phase = INPUT_PHASE.Moved;
                }
            }
            else
            {
                //Pressされた後にここにきたらReleaseとする
                if (isPressed)
                {
                    phase = INPUT_PHASE.Ended;
                }
                else
                {
                    phase         = INPUT_PHASE.NONE;
                    touchPosition = Vector3.zero;
                    isTouch       = false;
                }
            }
#endif
        }

        //for Mobile
        else if (inputType == INPUT_TYPE.INPUTTOUCH)
        {
            touchCount = Input.touchCount;

            if (touchCount >= 1)
            {
                touchPosition = Input.GetTouch(0).position;
                TouchPhase tphase = Input.GetTouch(0).phase;

                if (tphase == TouchPhase.Began)
                {
                    phase = INPUT_PHASE.Began;
                }
                else if (tphase == TouchPhase.Ended || tphase == TouchPhase.Canceled)
                {
                    phase = INPUT_PHASE.Ended;
                }
                else if (tphase == TouchPhase.Moved || tphase == TouchPhase.Stationary)
                {
                    phase = INPUT_PHASE.Moved;
                }
            }
            else
            {
                phase         = INPUT_PHASE.NONE;
                touchPosition = Vector3.zero;
                isTouch       = false;
            }
        }

        //for Mouse
        else if (inputType == INPUT_TYPE.MOUSE)
        {
            touchPosition = Input.mousePosition;

            if (Input.GetMouseButton(0))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    phase = INPUT_PHASE.Began;
                }
                else
                {
                    phase = INPUT_PHASE.Moved;
                }

                touchCount = 1;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                phase = INPUT_PHASE.Ended;
            }
            else
            {
                phase = INPUT_PHASE.NONE;
            }
        }

        if (touchCount < 0)
        {
            touchCount = 0;
        }
    }
    void Update()
    {
        if (hHook != 0) {
            // clean previous touches
            List<W7Touch> touchesToDelete = new List<W7Touch>();

            // remove duplicate touch ids (down + move, move + move, ...)
            Dictionary<uint, W7Touch> duplicateTouches = new Dictionary<uint, W7Touch>();
            foreach (W7Touch touch in touches) {
                if (duplicateTouches.ContainsKey(touch.Id)) {
                    touchesToDelete.Add(duplicateTouches[touch.Id]);
                    duplicateTouches[touch.Id] = touch;
                } else {
                    duplicateTouches.Add(touch.Id, touch);
                }
            }
            foreach (W7Touch touch in touchesToDelete) {
                touches.Remove(touch);
            }
            touchesToDelete.Clear();

            // remove ended touches
            foreach (W7Touch touch in touches) {
                if (touch.Phase == TouchPhase.Ended || touch.Phase == TouchPhase.Canceled) {
                    touchesToDelete.Add(touch);
                }
            }
            foreach (W7Touch touch in touchesToDelete) {
                touches.Remove(touch);
            }
            touchesToDelete.Clear();

            lock (rawTouchesQueue) {
                while (rawTouchesQueue.Count > 0) {
                    TOUCHINPUT[] rawTouches = rawTouchesQueue.Dequeue();
                    for (uint i = 0; i < rawTouches.Length; ++i) {
                        TOUCHINPUT rawTouch = rawTouches[i];
                        if (!touchIdMap.ContainsKey(rawTouch.dwID)) {
                            touchIdMap.Add(rawTouch.dwID, lastTouchId);
                            lastTouchId++;
                        }

                        W7Touch touch;
                        try {
                            touch = touches.Find(t => t.Id == touchIdMap[rawTouch.dwID]);
                        } catch {
                            touch = null;
                        }

                        Vector2 pos = new Vector2(rawTouch.x * 0.01f, rawTouch.y * 0.01f);
                        if (touch != null) {
                            if ((rawTouch.dwFlags & TOUCHEVENTF_DOWN) == TOUCHEVENTF_DOWN) {
                                touch.EndTouch();

                                touchIdMap.Add(rawTouch.dwID, lastTouchId);
                                lastTouchId++;
                                touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                touches.Add(touch);
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_MOVE) == TOUCHEVENTF_MOVE) {
                                if (touch.Phase == TouchPhase.Moved || touch.Phase == TouchPhase.Stationary) {
                                    touch.UpdateTouch(pos);
                                } else {
                                    touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                    touch.UpdateTouch(pos);
                                    touches.Add(touch);
                                }
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_UP) == TOUCHEVENTF_UP) {
                                touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                touch.EndTouch();
                                touches.Add(touch);
                                touchIdMap.Remove(rawTouch.dwID);
                            }
                        } else {
                            touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                            touches.Add(touch);
                            if ((rawTouch.dwFlags & TOUCHEVENTF_DOWN) == TOUCHEVENTF_DOWN) {
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_MOVE) == TOUCHEVENTF_MOVE) {
                                touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                touch.UpdateTouch(pos);
                                touches.Add(touch);
                            } else if ((rawTouch.dwFlags & TOUCHEVENTF_UP) == TOUCHEVENTF_UP) {
                                touch = new W7Touch(touchIdMap[rawTouch.dwID], pos);
                                touch.EndTouch();
                                touches.Add(touch);
                                touchIdMap.Remove(rawTouch.dwID);
                            }
                        }
                    }
                }
            }
            foreach (W7Touch touch in touches) {
                touch.Update();
                if (touch.Phase == TouchPhase.Canceled) {
                    var k = (from t in touchIdMap where t.Value == touch.Id select t.Key);
                    if (k.Count() > 0) {
                        touchIdMap.Remove(k.First());
                    }
                }
            }
        }
    }