def _update(self, timeSinceLastFrame): BaseCommand._update(self, timeSinceLastFrame) if self.paused: if self.pause <= 0: self.finish() return else: self.pause -= timeSinceLastFrame if self.is_pressed or self.press_time <= 0: state = render_engine._oisMouse.getMouseState() if self.pressed and not state.buttonDown(self.button_id): state.buttons += (1 << self.button_id) render_engine._inputListener.mousePressed( ois.MouseEvent(render_engine._oisMouse, state), self.button_id) elif not self.pressed and state.buttonDown(self.button_id): state.buttons = state.buttons & (~(1 << self.button_id)) render_engine._inputListener.mouseReleased( ois.MouseEvent(render_engine._oisMouse, state), self.button_id) self.paused = True self.press_time -= timeSinceLastFrame
def __init__(self, renderWindow, bufferedMouse, bufferedKeys, bufferedJoy): # Initialize the various listener classes we are a subclass from ogre.FrameListener.__init__(self) ogre.WindowEventListener.__init__(self) OIS.MouseListener.__init__(self) OIS.KeyListener.__init__(self) OIS.JoyStickListener.__init__(self) self.renderWindow = renderWindow # Create the inputManager using the supplied renderWindow windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.inputManager = OIS.createPythonInputSystem([("WINDOW",str(windowHnd))]) # Attempt to get the mouse/keyboard input objects, # and use this same class for handling the callback functions. # These functions are defined later on. try: if bufferedMouse: self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, bufferedMouse) self.mouse.setEventCallback(self) if bufferedKeys: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, bufferedKeys) self.keyboard.setEventCallback(self) if bufferedJoy: self.joy = self.inputManager.createInputObjectJoyStick(OIS.OISJoyStick, bufferedJoy) self.joy.setEventCallback(self) except Exception, e: # Unable to obtain mouse/keyboard/joy input raise e
def initialize(self): self.mouseMoved = False windowHandle = 0 renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeInt("WINDOW") oisOptions = [("WINDOW", str(windowHandle))] if sys.platform == "win32": oisOptions.append(("w32_mouse", "DISCL_FOREGROUND")) oisOptions.append(("w32_mouse", "DISCL_NONEXCLUSIVE")) oisOptions.append(("w32_keyboard", "DISCL_FOREGROUND")) oisOptions.append(("w32_keyboard", "DISCL_NONEXCLUSIVE")) else: oisOptions.append(("x11_mouse_grab", "false")) oisOptions.append(("x11_mouse_hide", "false")) oisOptions.append(("x11_keyboard_grab", "false")) oisOptions.append(("XAutoRepeatOn", "true")) self.inputManager = OIS.createPythonInputSystem(oisOptions) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately self.keyboard = None self.mouse = None try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse,False) except Exception, e: print "No Keyboard or mouse!!!!" raise e
def _setupInput(self): """Setup the OIS library for input""" options = [("WINDOW", str(self.renderWindow.getCustomAttributeInt("WINDOW")))] if os.name.startswith("posix"): options.append(("x11_mouse_grab", str("false"))) options.append(("x11_keyboard_grab", str("false"))) elif os.name.startswith("nt"): pass # FIXME: mouse problems in windows #options.append(("w32_mouse", str("DISCL_FOREGROUND"))) #options.append(("w32_mouse", str("DISCL_NONEXCLUSIVE"))) self.inputManager = ois.createPythonInputSystem(options) self.enableKeyboard = True self.enableMouse = True if self.enableKeyboard: self.keyboard = self.inputManager.createInputObjectKeyboard( ois.OISKeyboard, True) self.keyboard.setEventCallback(self) if self.enableMouse: self.mouse = self.inputManager.createInputObjectMouse( ois.OISMouse, True) self.mouse.setEventCallback(self) state = self.mouse.getMouseState() state.width = self.renderWindow.getWidth() state.height = self.renderWindow.getHeight()
def _setupInput(self): # ignore buffered input windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.InputManager = \ OIS.createPythonInputSystem([("WINDOW",str(windowHnd))]) #pl = OIS.ParamList() #windowHndStr = str ( windowHnd) #pl.insert("WINDOW", windowHndStr) #im = OIS.InputManager.createInputSystem( pl ) #Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, False ) self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, False ) try : self.Joy = self.InputManager.createInputObjectJoyStick( OIS.OISJoyStick, False ) except: self.Joy = False #Set initial mouse clipping size self.windowResized(self.renderWindow) self.showDebugOverlay(True) #Register as a Window listener ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self);
def setup(self): if self.__setup: raise Exception ("InputManager.setup(...) run twice") self.__setup = True # From the ogre demo Simple Application. # I assume it fixes an issue on 64bit computers... import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True if int64: windowHnd = App().renderManager.window.getCustomAttributeUnsignedLong("WINDOW") else: windowHnd = App().renderManager.window.getCustomAttributeInt("WINDOW") params = [("WINDOW",str(windowHnd)), ("w32_keyboard","DISCL_FOREGROUND"), ("w32_keyboard", "DISCL_NONEXCLUSIVE"), ("x11_keyboard_grab", "false"), ("w32_mouse","DISCL_FOREGROUND"), ("w32_mouse", "DISCL_EXCLUSIVE"), ("x11_mouse_grab", "true"), ("x11_mouse_hide", "true")] self.system = OIS.createPythonInputSystem( params ) self.__keyb = self.system.createInputObjectKeyboard(OIS.OISKeyboard, False) self.__mous = self.system.createInputObjectMouse(OIS.OISMouse, True) self.__mouseListener = self.__MouseListener(self.__mous) self.__mous.setEventCallback(self.__mouseListener) self.__setupKeyboard()
def init(self): # initialize an input system windowHandle = 0 renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True if int64: windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") else: windowHandle = renderWindow.getCustomAttributeInt("WINDOW") t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] paramList = [("WINDOW", str(windowHandle))] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately self.keyboard = None self.mouse = None try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, True) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, True) except Exception, e: print "No Keyboard or mouse!!!!" raise e
def initOis(): global _inputManager global _oisMouse global _oisKeyboard # initialize input _logManager.logInit('Input system') windowHwnd = _ogreRenderWindow.getCustomAttributeInt("WINDOW") if sys.platform == 'win32': _inputManager = ois.createPythonInputSystem([("WINDOW", str(windowHwnd)), # ("w32_mouse", "DISCL_FOREGROUND"), # ("w32_mouse", "DISCL_NONEXCLUSIVE"), # ("w32_keyboard", "DISCL_FOREGROUND"), # ("w32_keyboard", "DISCL_NONEXCLUSIVE")]) ]) else: raise AssertionError("Unsupported platform") # create devices _oisKeyboard = _inputManager.createInputObjectKeyboard( ois.OISKeyboard, True ) _oisMouse = _inputManager.createInputObjectMouse( ois.OISMouse, True ) width, height, depth, left, top = _ogreRenderWindow.getMetrics(1,1,1,1,1) ms = _oisMouse.getMouseState() ms.width = width ms.height = height _oisMouse.setEventCallback(_inputListener) _oisKeyboard.setEventCallback(_inputListener)
def init(self): windowHandle = 0 renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") paramList = [("WINDOW", str(windowHandle))] if os.name == "nt": t = [("w32_mouse","DISCL_FOREGROUND"), ("w32_mouse", "DISCL_NONEXCLUSIVE")] else: #t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "true")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately self.keyboard = None self.mouse = None try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, True) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, True) except Exception, e: print "No Keyboard or mouse!!!!" raise e
def _initializeOIS(self): """ Creates the root OIS InputManager """ # Window handle params = [("WINDOW",self._config['_RootWindowHandle']), ('XAutoRepeatOn','true')] # mouse grab/hide only on fullscreen mode # Notice the current code is platform dependent!!! # It will do nothing on non-linux systems since the options have # other names, I think that upstream (OIS maintainers), should have # used a set of generic options mapped to the corresponding OS attrs if self._config['graphics.fullscreen'].lower() != 'true' : params.append(('x11_mouse_grab','false')) #params.append(('x11_mouse_hide','false')) params.append(('x11_keyboard_grab','false')) self._InputManager = OIS.createPythonInputSystem(params) self._printOISVersion() self._actionMapper = ActionMapper(self._config) self._actionMapper.initialize() self._InputConsumers = [self._actionMapper] return self._initalizeAndRegisterListenners()
def setupInput(self): windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.InputManager = \ OIS.createPythonInputSystem([("WINDOW",str(windowHnd))]) self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, True ) self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, True )
def setupInput(self): # Create the inputManager using the supplied renderWindow windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHnd)), \ ("w32_mouse", "DISCL_FOREGROUND"), \ ("w32_mouse", "DISCL_NONEXCLUSIVE"), \ ("w32_keyboard", "DISCL_FOREGROUND"), \ ("w32_keyboard", "DISCL_NONEXCLUSIVE"),] # @todo: add mac/linux parameters self.inputManager = OIS.createPythonInputSystem(paramList) # Attempt to get the mouse/keyboard input device objects. try: self.mouse = self.inputManager.createInputObjectMouse( OIS.OISMouse, True) self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, True) except Exception: # Unable to obtain mouse/keyboard input raise # Use an InputHandler object to handle the callback functions. self.inputHandler = InputHandler(mouse=self.mouse, keyboard=self.keyboard, scene=self, player=self.player) self.mouse.setEventCallback(self.inputHandler) self.keyboard.setEventCallback(self.inputHandler)
def init(self): renderWindow = self.engine.gfxMgr.renderWindow if is64Bit(): windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") else: windowHandle = renderWindow.getCustomAttributeInt("WINDOW") paramList = [('WINDOW', str(windowHandle))] ''' if sys.platform == 'win32': paramList.extend([('w32_mouse', 'DISCL_FOREGROUND'), ('w32_mouse', 'DISCL_NONEXCLUSIVE')]) else: paramList.extend([('x11_mouse_grab', 'false'), ('x11_mouse_hide', 'false')]) ''' self.oisMgr = OIS.createPythonInputSystem(paramList) try: self.keyboard = self.oisMgr.createInputObjectKeyboard(OIS.OISKeyboard, True) self.mouse = self.oisMgr.createInputObjectMouse(OIS.OISMouse, True) try: self.joystick = self.oisMgr.createInputObjectJoyStick(OIS.OISJoyStick, True) except: self.joystick = False except Exception, e: print "ERROR: Unable to initialize mouse, keyboard, or joystick" raise e
def __init__(self, sceneManager): # Initialize the various listener classes we are a subclass from ogre.FrameListener.__init__(self) ogre.WindowEventListener.__init__(self) self.renderWindow = ogre.Root.getSingleton().getAutoCreatedWindow() self.sceneManager = sceneManager self.camera = self.sceneManager.getCamera("PrimaryCamera") self.cameraNode = self.sceneManager.getSceneNode("PrimaryCamera") self.viewport = self.camera.getViewport() # Create an empty list of nodes self.nodes = [] # Create an empty list of GUI elements. self.gui_elements = [] # Set up the overlay for the GUI. self.setupOverlay() # Set up the scene. self.setupScene() # Set up the GUI. self.setupGUI() # Create the inputManager using the supplied renderWindow windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHnd)), \ ("w32_mouse", "DISCL_FOREGROUND"), \ ("w32_mouse", "DISCL_NONEXCLUSIVE"), \ ("w32_keyboard", "DISCL_FOREGROUND"), \ ("w32_keyboard", "DISCL_NONEXCLUSIVE"),] # @todo: add mac/linux parameters self.inputManager = OIS.createPythonInputSystem(paramList) # Attempt to get the mouse/keyboard input device objects. try: self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, True) self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, True) except Exception: # Unable to obtain mouse/keyboard input raise # Use an InputHandler object to handle the callback functions. self.inputHandler = InputHandler(mouse=self.mouse, keyboard=self.keyboard, scene=self, player=self.player) self.mouse.setEventCallback(self.inputHandler) self.keyboard.setEventCallback(self.inputHandler) # Set up initial window size. self.windowResized(self.renderWindow) # Set this to True when we get an event to exit the application self.quit = False # Listen for any events directed to the window manager's close button ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self)
def start(self, window, camera ): ## create self.Mouse windowHnd = window.getCustomAttributeInt("WINDOW") self.InputManager = \ OIS.createPythonInputSystem([("WINDOW",str(windowHnd))]) ##Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, True ) self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, True )
def init(self): # Skapa och initialisera OIS, som är vårat bibliotek för indata från # saker som tagentbord och mus. hWnd = self.window.getCustomAttributeInt("WINDOW"); # Handle för vårat fönster self.inputSystem = OIS.createPythonInputSystem([("WINDOW",str(hWnd))]); # Skapa objekt för input från tagentbord self.keyboard = self.inputSystem.createInputObjectKeyboard(OIS.OISKeyboard,True); # Lägg detta objekt för callbacks self.keyboard.setEventCallback(self);
def __init__(self, app, hnd): OIS.KeyListener.__init__(self) OIS.MouseListener.__init__(self) self.app = app self.input_mgr = OIS.createPythonInputSystem([("WINDOW", str(hnd))]) # Setup Unbuffered Keyboard and Buffered Mouse Input self.keyboard = \ self.input_mgr.createInputObjectKeyboard(OIS.OISKeyboard,True) self.keyboard.setEventCallback(self)
def _setupInput(self): # Initialize OIS. windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.InputManager = OIS.createPythonInputSystem([("WINDOW", str(windowHnd))]) self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, self.bufferedKeys) self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, self.bufferedMouse) self.Joy = False
def initInput(): # window handle winHandle = mgr.window.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(winHandle))] # create input "manager" or "hook", as I call it mgr.input = OIS.createPythonInputSystem(paramList) mgr.keys = mgr.input.createInputObjectKeyboard(OIS.OISKeyboard, True) mgr.mouse = mgr.input.createInputObjectMouse(OIS.OISMouse, True)
def __init__(self, application): ogre.FrameListener.__init__(self) self._keeprendering = True self._framenumber = 0 self._bufferedkeys = True self.application = application windowhandle = self.application.window.getCustomAttributeInt("WINDOW") self._inputmanager = ois.createPythonInputSystem([("WINDOW",str(windowhandle))]) self.keyboard = self._inputmanager.createInputObjectKeyboard(ois.OISKeyboard, self._bufferedkeys)
def init(self): # Skapa och initialisera OIS, som är vårat bibliotek för indata från # saker som tagentbord och mus. hWnd = self.window.getCustomAttributeInt("WINDOW"); # Handle för vårat fönster self.inputSystem = OIS.createPythonInputSystem([("WINDOW",str(hWnd))]); # Skapa objekt för input från tagentbord self.keyboard = self.inputSystem.createInputObjectKeyboard(OIS.OISKeyboard,True); # Lägg detta objekt för callbacks self.keyboard.setEventCallback(self); rot = ogre.Quaternion(-math.pi, (0, 1, 0)); self.camera.update(ogre.Vector3(0,100,0), rot, ogre.Vector3(0,0,0),ogre.Vector3(0,0,0));
def _update(self, timeSinceLastFrame): BaseCommand._update(self, timeSinceLastFrame) if self.paused: if self.pause <= 0: self.finish() else: self.pause -= timeSinceLastFrame if self.press_time <= 0 and not self.paused: if self.pressed: render_engine._inputListener.keyPressed( ois.KeyEvent(render_engine._oisKeyboard, self.button_id, True)) elif not self.pressed: render_engine._inputListener.keyReleased( ois.KeyEvent(render_engine._oisKeyboard, self.button_id, True)) self.paused = True self.press_time -= timeSinceLastFrame
def setupInputSystem(self): windowHandle = 0 renderWindow = self.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") paramList = [("WINDOW", str(windowHandle))] t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, False) except Exception, e: raise e
def __init__(self, win, cam, sm, app): ogre.FrameListener.__init__(self) OIS.KeyListener.__init__(self) OIS.MouseListener.__init__(self) self.app = app self.sceneManager = sm self.mWindow = win self.camera = cam self.mShutdownRequested = False self.mLMBDown = False self.mRMBDown = False self.mProcessMovement = False self.mUpdateMovement = False self.mMoveFwd = False self.mMoveBck = False self.mMoveLeft = False self.mMoveRight = False self.mLastMousePositionSet = False self.mAvgFrameTime = 0.01 self.mWriteToFile = False self.mTranslateVector = ogre.Vector3().ZERO self.mQuit = False self.bReload = False self.mSkipCount = 0 self.mUpdateFreq = 10 self.mRotX = 0 self.mRotY = 0 windowHnd = self.mWindow.getCustomAttributeInt("WINDOW") self.mInputManager = OIS.createPythonInputSystem([("WINDOW", str(windowHnd))]) ##Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) self.Keyboard = self.mInputManager.createInputObjectKeyboard( OIS.OISKeyboard, True) self.Mouse = self.mInputManager.createInputObjectMouse( OIS.OISMouse, True) # width, height, depth, left, top = self.mWindow.getMetrics() ##Set Mouse Region.. if window resizes, we should alter this to reflect as well # ms = self.Mouse.getMouseState() # ms.width = width # # ms.height = height self.Mouse.setEventCallback(self) self.Keyboard.setEventCallback(self) self.mMoveSpeed = 400.0
def initEngine(self): import os #add me to ogre's frame listener list self.engine.gfxSystem.root.addFrameListener(self) import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True windowHandle = 0 renderWindow = self.engine.gfxSystem.root.getAutoCreatedWindow() if int64: windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") else: windowHandle = renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHandle))] t = [("x11_mouse_grab", "true"), ("x11_mouse_hide", "false")] paramList.extend(t) ''' windowHandle = 0 renderWindow = self.engine.gfxSystem.root.getAutoCreatedWindow() # or self.renderWindow windowHandle = renderWindow.getCustomAttributeInt("WINDOW") if os.name == "nt": t = [("w32_mouse","DISCL_FOREGROUND"), ("w32_mouse", "DISCL_NONEXCLUSIVE")] else: t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] #t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "true")] paramList = [("WINDOW", str(windowHandle))] paramList.extend(t) ''' self.inputManager = OIS.createPythonInputSystem(paramList) self.keyboard = None self.mouse = None self.joystick = None try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, True) except Exception, e: print "----------------------------------->No Keyboard" raise e
def setupInputSystem(self): windowHandle = 0 renderWindow = self.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") paramList = [("WINDOW", str(windowHandle))] t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) try: self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, False) self.mouse = self.inputManager.createInputObjectMouse( OIS.OISMouse, False) except Exception, e: raise e
def setupInputSystem(self): windowHandle = 0 renderWindow = self.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHandle))] self.inputManager = OIS.createPythonInputSystem(paramList) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately try: Input.init( self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False), self.inputManager.createInputObjectMouse(OIS.OISMouse, False) ) except Exception, e: raise e
def _setupInput(self): # ignore buffered input # FIXME: This should be fixed in C++ propbably import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True if int64: windowHnd = self.renderWindow.getCustomAttributeUnsignedLong("WINDOW") else: windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") # # Here is where we create the OIS input system using a helper function that takes python list of tuples # t= self._inputSystemParameters() params = [("WINDOW",str(windowHnd))] params.extend(t) self.InputManager = OIS.createPythonInputSystem( params ) # # an alternate way is to use a multimap which is exposed in ogre # # pl = ogre.SettingsMultiMap() # windowHndStr = str(windowHnd) # pl.insert("WINDOW", windowHndStr) # for v in self._inputSystemParameters(): # pl.insert(v[0],v[1]) # im = OIS.InputManager.createInputSystem( pl ) #Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, self.bufferedKeys ) self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, self.bufferedMouse ) try: self.Joy = self.InputManager.createInputObjectJoyStick( OIS.OISJoyStick, self.bufferedJoy ) except: self.Joy = False # #Set initial mouse clipping size self.windowResized(self.renderWindow) self.showDebugOverlay(True) #Register as a Window listener ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self);
def __init__(self, render_window, bullet, buffer_mouse=True, buffer_keys=True, buffer_joystick=False): # Initialize the various listener classes we are a subclass from ogre.FrameListener.__init__(self) ogre.WindowEventListener.__init__(self) OIS.MouseListener.__init__(self) OIS.KeyListener.__init__(self) OIS.JoyStickListener.__init__(self) self.quitApplication = False """Set to True when the application should exit.""" self.renderWindow = render_window self.bullet_world = bullet # Listen for window close events. ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self) # Create the inputManager using the supplied renderWindow. windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.inputManager = OIS.createPythonInputSystem([("WINDOW", str(windowHnd))]) self.mouse = None self.keyboard = None self.joystick = None # Attempt to get the mouse/keyboard/joystick input objects: try: if buffer_mouse: self.mouse = self.inputManager.createInputObjectMouse( OIS.OISMouse, True) self.mouse.setEventCallback(self) if buffer_keys: self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, True) self.keyboard.setEventCallback(self) if buffer_joystick: self.joystick = self.inputManager.createInputObjectJoyStick( OIS.OISJoyStick, True) self.joystick.setEventCallback(self) except Exception, e: logging.exception("Unable to create keyboard/mouse/joystick object.", e) raise e
def setupInputSystem(self): windowHandle = 0 self.renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() windowHandle = self.renderWindow.getCustomAttributeUnsignedLong("WINDOW") paramList = [("WINDOW", str(windowHandle))] if sys.platform == 'win32': t = [('w32_mouse', 'DISCL_FOREGROUND'), ('w32_mouse', 'DISCL_NONEXCLUSIVE')] else: t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, False) except Exception, e: raise e
def setMousePosition(self, pos): """Sets new mouse position @param pos: new mouse position @type pos: (int, int) """ state = render_engine._oisMouse.getMouseState() # create Axes state.X.abs = int(pos[0]) state.X.rel = int(pos[0] - self.current_pos[0]) state.Y.abs = int(pos[1]) state.Y.rel = int(pos[1] - self.current_pos[1]) render_engine._inputListener.mouseMoved(ois.MouseEvent(render_engine._oisMouse, state))
def _setupInput(self): # Initialize OIS. windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.InputManager = OIS.createPythonInputSystem([("WINDOW", str(windowHnd))]) # Create all devices, only catch joystick exceptions since most people use Key/Mouse. self.Keyboard = self.InputManager.createInputObjectKeyboard(OIS.OISKeyboard, self.bufferedKeys) self.Mouse = self.InputManager.createInputObjectMouse(OIS.OISMouse, self.bufferedMouse) try: self.Joy = self.InputManager.createInputObjectJoyStick(OIS.OISJoyStick, self.bufferedJoy) except: self.Joy = False #Set initial mouse clipping size. # self.windowResized(self.renderWindow) # Register as a Window listener. ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self);
def _setupInput(self): windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.InputManager = \ OIS.createPythonInputSystem([("WINDOW",str(windowHnd))]) #Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) #self.Keyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, False ) self.BufferedKeyboard = self.InputManager.createInputObjectKeyboard( OIS.OISKeyboard, True ) self.Mouse = self.InputManager.createInputObjectMouse( OIS.OISMouse, True ) try : self.Joy = self.InputManager.createInputObjectJoyStick( OIS.OISJoyStick, True ) except: self.Joy = False #Set initial mouse clipping size self.windowResized(self.renderWindow) #Register as a Window listener ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self);
def init(self): windowHandle = 0 renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeUnsignedLong("WINDOW") paramList = [("WINDOW", str(windowHandle))] t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) self.keyboard = None self.mouse = None try: self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, True) self.mouse = self.inputManager.createInputObjectMouse( OIS.OISMouse, True) except Exception, e: print "No Keyboard or Mouse!!!!" raise e
def initialize(self): windowHandle = 0 renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHandle))] paramList.append(("x11_mouse_grab", "false")) paramList.append(("x11_mouse_hide", "false")) paramList.append(("x11_keyboard_grab", "false")) self.inputManager = OIS.createPythonInputSystem(paramList) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately self.keyboard = None self.mouse = None try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, True) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, True) except Exception, e: print "No Keyboard or mouse!!!!" raise e
def __init__(self, app, renderWindow, bufferedMouse, bufferedKeys, bufferedJoy): ogre.FrameListener.__init__(self) ogre.WindowEventListener.__init__(self) OIS.MouseListener.__init__(self) OIS.KeyListener.__init__(self) OIS.JoyStickListener.__init__(self) self.app = app self.renderWindow = renderWindow # Init input system import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True # Create the inputManager using the supplied renderWindow if int64: windowHnd = self.renderWindow.getCustomAttributeUnsignedLong("WINDOW") else: windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") t = self._inputSystemParameters() params = [("WINDOW",str(windowHnd))] params.extend(t) self.inputManager = OIS.createPythonInputSystem(params) try: if bufferedMouse: self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, bufferedMouse) self.mouse.setEventCallback(self) if bufferedKeys: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, bufferedKeys) self.keyboard.setEventCallback(self) if bufferedJoy: self.joy = self.inputManager.createInputObjectJoyStick(OIS.OISJoyStick, bufferedJoy) self.joy.setEventCallback(self) except Exception, e: # Unable to obtain mouse/keyboard/joy input raise e
def initialize(self): windowHandle = 0 renderWindow = self.engine.gfxMgr.root.getAutoCreatedWindow() windowHandle = renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHandle))] paramList.append(("x11_mouse_grab", "false")) paramList.append(("x11_mouse_hide", "false")) paramList.append(("x11_keyboard_grab", "false")) self.inputManager = OIS.createPythonInputSystem(paramList) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately self.keyboard = None self.mouse = None try: self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, True) self.mouse = self.inputManager.createInputObjectMouse( OIS.OISMouse, True) except Exception, e: print "No Keyboard or mouse!!!!" raise e
def setupInput(self): # Create the inputManager using the supplied renderWindow windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHnd)), \ ("w32_mouse", "DISCL_FOREGROUND"), \ ("w32_mouse", "DISCL_NONEXCLUSIVE"), \ ("w32_keyboard", "DISCL_FOREGROUND"), \ ("w32_keyboard", "DISCL_NONEXCLUSIVE"),] # @todo: add mac/linux parameters self.inputManager = OIS.createPythonInputSystem(paramList) # Attempt to get the mouse/keyboard input device objects. try: self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, True) self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, True) except Exception: # Unable to obtain mouse/keyboard input raise # Use an InputHandler object to handle the callback functions. self.inputHandler = InputHandler(self.mouse, self.keyboard, self) self.mouse.setEventCallback(self.inputHandler) self.keyboard.setEventCallback(self.inputHandler)
def __init__(self, renderWindow, bufferedMouse, bufferedKeys, bufferedJoy): # Initialize the various listener classes we are a subclass from ogre.FrameListener.__init__(self) ogre.WindowEventListener.__init__(self) OIS.MouseListener.__init__(self) OIS.KeyListener.__init__(self) OIS.JoyStickListener.__init__(self) self.renderWindow = renderWindow # Create the inputManager using the supplied renderWindow windowHnd = self.renderWindow.getCustomAttributeInt("WINDOW") self.inputManager = OIS.createPythonInputSystem([("WINDOW", str(windowHnd))]) # Attempt to get the mouse/keyboard input objects, # and use this same class for handling the callback functions. # These functions are defined later on. try: if bufferedMouse: self.mouse = self.inputManager.createInputObjectMouse( OIS.OISMouse, bufferedMouse) self.mouse.setEventCallback(self) if bufferedKeys: self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, bufferedKeys) self.keyboard.setEventCallback(self) if bufferedJoy: self.joy = self.inputManager.createInputObjectJoyStick( OIS.OISJoyStick, bufferedJoy) self.joy.setEventCallback(self) except Exception, e: # Unable to obtain mouse/keyboard/joy input raise e
def init(self): self.initKeyStates() self.updateCamNode() int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True if int64: self.windowHandle = self.renderWindow.getCustomAttributeUnsignedLong("WINDOW") else: self.windowHandle = self.renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(self.windowHandle))] t = [("x11_mouse_grab", "false"), ("x11_mouse_hide", "false")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) # Now InputManager is initialized for use. Keyboard and Mouse objects # must still be initialized separately try: self.keyboard = self.inputManager.createInputObjectKeyboard(OIS.OISKeyboard, False) self.mouse = self.inputManager.createInputObjectMouse(OIS.OISMouse, False) except Exception, e: raise e
def _setup_ois(self): # Hook OIS up to the window created by Ogre windowHnd = self._window.getCustomAttributeInt("WINDOW") params = [('WINDOW', windowHnd)] plat = platform.system() if 'Linux' == plat: # if config.get('debug', False): # self.logger.info("OIS Keyboard grab off") params.extend([('x11_keyboard_grab', 'false'), ('x11_mouse_grab', 'false'), ('XAutoRepeatOn', 'true')]) elif 'Windows' == plat or 'Microsoft' == plat: pass elif 'Darwin' == plat: pass else: raise InputSystem("Platform '%s' not supposed" % plat) self.input_mgr = OIS.createPythonInputSystem(params) # Setup Unbuffered Keyboard and Buffered Mouse Input self.keyboard = \ self.input_mgr.createInputObjectKeyboard(OIS.OISKeyboard, True)
def init_input_manager(self, render_window): """Initializes the input manager for creating the devices""" import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True if int64: window_handle = render_window.getCustomAttributeUnsignedLong("WINDOW") else: window_handle = render_window.getCustomAttributeInt("WINDOW") if os.name == "nt": t = [("w32_mouse","DISCL_FOREGROUND"), ("w32_mouse", "DISCL_NONEXCLUSIVE")] else: t = [("x11_mouse_grab", "true"), ("x11_mouse_hide", "true"), ("x11_keyboard_grab", "false"), ("xAutoRepeatOn", "true")] #t = [("x11_mouse_grab", "false"), # ("x11_mouse_hide", "true")] param_list = [("WINDOW", str(window_handle))] param_list.extend(t) self.input_manager = OIS.createPythonInputSystem(param_list)
def init(self): self.root = self.engine.gfxMgr.root self.keepRendering = True pygame.init() self.joysticks = [] self.p1LR = 0 self.p2LR = 0 self.joystick_count = pygame.joystick.get_count() print str(self.joystick_count) + " joysticks found" for i in range(0, pygame.joystick.get_count()): # create an Joystick object in our list self.joysticks.append(pygame.joystick.Joystick(i)) # initialize them all (-1 means loop forever) self.joysticks[-1].init() # print a statement telling what the name of the controller is print "Detected joystick '", self.joysticks[-1].get_name(), "'" import platform int64 = False for bit in platform.architecture(): if '64' in bit: int64 = True windowHandle = 0 renderWindow = self.root.getAutoCreatedWindow() if int64: windowHandle = renderWindow.getCustomAttributeUnsignedLong( "WINDOW") else: windowHandle = renderWindow.getCustomAttributeInt("WINDOW") paramList = [("WINDOW", str(windowHandle))] t = [("x11_mouse_grab", "true"), ("x11_mouse_hide", "false")] paramList.extend(t) self.inputManager = OIS.createPythonInputSystem(paramList) #This sets up the InputManager for use, but to actually use OIS to get input for the #keyboard and mouse, you'll need to create the following objects # try: # self.joystick = self.inputManager.createInputObjectJoyStick(OIS.OISJoyStick, True) # print "----------------------------------->Made joystick object" # except Exception, e: self.joystick = None # print "----------------------------------->No Joy, Don't Worry Be Happy" # print "----------------------------------->Who uses joysticks anyways? - so 1995" # if self.joystick: # self.jMgr = JoyStickListener(self) # try: # self.joy2stick = self.inputManager.createInputObjectJoyStick(OIS.OISJoyStick, True) # print "----------------------------------->Made joystick object" # except Exception, e: # self.joy2stick = None # print "----------------------------------->No Joy, Don't Worry Be Happy" # print "----------------------------------->Who uses joysticks anyways? - so 1995" # if self.joy2stick: # self.jMgr2 = Joy2StickListener(self) self.keyboard = self.inputManager.createInputObjectKeyboard( OIS.OISKeyboard, True) # self.jMgr2 = Joy2StickListener(self) # self.jMgr = JoyStickListener(self) self.createFrameListener()