Example #1
1
bool EventDispatcher::DispatchSDLEvent(const SDL_Event &event)
{
	switch (event.type) {
		case SDL_KEYDOWN:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_DOWN, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod))));

		case SDL_KEYUP:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_UP, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod))));

		case SDL_TEXTINPUT:
			Uint32 unicode;
			Text::utf8_decode_char(&unicode, event.text.text);
			return Dispatch(TextInputEvent(unicode));

		case SDL_MOUSEWHEEL:
			return Dispatch(MouseWheelEvent(event.wheel.y > 0 ? MouseWheelEvent::WHEEL_UP : MouseWheelEvent::WHEEL_DOWN, m_lastMousePosition));

		case SDL_MOUSEBUTTONDOWN:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_DOWN, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEBUTTONUP:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_UP, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEMOTION:
			return Dispatch(MouseMotionEvent(Point(event.motion.x,event.motion.y), Point(event.motion.xrel, event.motion.yrel)));
	}

	return false;
}
Example #2
1
bool EventDispatcher::DispatchSDLEvent(const SDL_Event &event)
{
	switch (event.type) {
		case SDL_KEYDOWN:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_DOWN, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod)), event.key.repeat));

		case SDL_KEYUP:
			return Dispatch(KeyboardEvent(KeyboardEvent::KEY_UP, KeySym(event.key.keysym.sym, SDL_Keymod(event.key.keysym.mod)), event.key.repeat));

		case SDL_TEXTINPUT:
			Uint32 unicode;
			Text::utf8_decode_char(&unicode, event.text.text);
			return Dispatch(TextInputEvent(unicode));

		case SDL_MOUSEWHEEL:
			return Dispatch(MouseWheelEvent(event.wheel.y > 0 ? MouseWheelEvent::WHEEL_UP : MouseWheelEvent::WHEEL_DOWN, m_lastMousePosition));

		case SDL_MOUSEBUTTONDOWN:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_DOWN, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEBUTTONUP:
			return Dispatch(MouseButtonEvent(MouseButtonEvent::BUTTON_UP, MouseButtonFromSDLButton(event.button.button), Point(event.button.x,event.button.y)));

		case SDL_MOUSEMOTION:
			return Dispatch(MouseMotionEvent(Point(event.motion.x,event.motion.y), Point(event.motion.xrel, event.motion.yrel)));

		case SDL_JOYAXISMOTION:
			// SDL joystick axis value is documented to have the range -32768 to 32767
			// unfortunately this places the centre at -0.5, not at zero, which is clearly nuts...
			// so since that doesn't make any sense, we assume the range is *actually* -32767 to +32767,
			// and scale it accordingly, clamping the output so that if we *do* get -32768, it turns into -1
			return Dispatch(JoystickAxisMotionEvent(event.jaxis.which, Clamp(event.jaxis.value * (1.0f / 32767.0f), -1.0f, 1.0f), event.jaxis.axis));

		case SDL_JOYHATMOTION:
			return Dispatch(JoystickHatMotionEvent(event.jhat.which, JoystickHatMotionEvent::JoystickHatDirection(event.jhat.value), event.jhat.hat));

		case SDL_JOYBUTTONDOWN:
			return Dispatch(JoystickButtonEvent(event.jbutton.which, JoystickButtonEvent::BUTTON_DOWN, event.jbutton.button));

		case SDL_JOYBUTTONUP:
			return Dispatch(JoystickButtonEvent(event.jbutton.which, JoystickButtonEvent::BUTTON_UP, event.jbutton.button));
	}

	return false;
}
	bool UserInputListener::fireKeyUp( KeyboardKey p_key, bool p_ctrl, bool p_alt, bool p_shift )
	{
		bool result = false;

		if ( doHasHandlers() )
		{
			auto active = m_activeHandler.lock();

			if ( active )
			{
				if ( p_key == KeyboardKey::eControl )
				{
					m_keyboard.m_ctrl = false;
				}

				if ( p_key == KeyboardKey::eAlt )
				{
					m_keyboard.m_alt = false;
				}

				if ( p_key == KeyboardKey::eShift )
				{
					m_keyboard.m_shift = false;
				}

				active->pushEvent( KeyboardEvent( KeyboardEventType::eReleased, p_key, m_keyboard.m_ctrl, m_keyboard.m_alt, m_keyboard.m_shift ) );
				result = true;
			}
		}

		return result;
	}
Example #4
0
// Generates KEYUP
//##ModelId=474D302503AA
void CSendKeys::SendKeyUp(BYTE VKey)
{
  BYTE ScanCode = LOBYTE(::MapVirtualKey(VKey, 0));

  KeyboardEvent(VKey, 
                ScanCode, 
                KEYEVENTF_KEYUP | (IsVkExtended(VKey) ? KEYEVENTF_EXTENDEDKEY : 0));
}
Example #5
0
void KeyboardController::handleEvent(void) {
	int scode = 0, pressFlag = 0;
    
    // handle keyboard event:
	// 1. press key
	// 2. release key
	if(kbQueue != NULL && QueueEmpty(kbQueue) == false)
	{
		scode = PopQueue(kbQueue);
		pressFlag = scode & 0x80;
		scode &= 0x7f;
		if (pressFlag)
			KeyboardEvent(false, scode);
		else
			KeyboardEvent(true, scode);
	}
}
Example #6
0
void CSelfTestMenu::OnButton8(int iEvent, unsigned char * pEventData, int iDataLen)
{
	KeyboardEvent(1);
	DBG_PRINT(("KeyboardEvent() over"));
	this->ReFresh();
	DBG_PRINT(("KeyboardEvent() ReFresh"));

}
Example #7
0
//Can't set directly LAYER_CHANGED to 1, due to dsp decoding.
//This function stay on PC.
void choose_layer (ConfigSVC *Config)
{
	if ( KeyboardEvent() ) {
		printf("DqId to decode ?\n");
		scanf("%d", &Config -> SetLayer);
		printf("Temporal Command ?\n");
		printf("0: No change, 1: Switch down, 2: Switch up, 3: defined specific one\n");
		scanf("%d", &Config -> TemporalCom);
		if(Config -> TemporalCom == 3){
			printf("Enter the maximal temporal_id to decode\n");
			scanf("%d", &Config -> TemporalId);
		}
	}
}
	bool UserInputListener::fireChar( KeyboardKey p_key, String const & p_char )
	{
		bool result = false;

		if ( doHasHandlers() )
		{
			auto active = m_activeHandler.lock();

			if ( active )
			{
				active->pushEvent( KeyboardEvent( KeyboardEventType::eChar, p_key, p_char, m_keyboard.m_ctrl, m_keyboard.m_alt, m_keyboard.m_shift ) );
				result = true;
			}
		}

		return result;
	}
Example #9
0
//##ModelId=474D302503BA
void CSendKeys::SendKeyDown(BYTE VKey, WORD NumTimes, bool GenUpMsg, bool bDelay)
{
  WORD Cnt = 0;
  BYTE ScanCode = 0;
  bool NumState = false;

  if (VKey == VK_NUMLOCK)
  {
    DWORD dwVersion = ::GetVersion();

    for (Cnt=1; Cnt<=NumTimes; Cnt++)
    {
      if (bDelay)
        CarryDelay();
      // snippet based on:
      // http://www.codeproject.com/cpp/togglekeys.asp
      if (dwVersion < 0x80000000)
      {
        ::keybd_event(VKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
        ::keybd_event(VKey, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
      }
      else
      {
        // Win98 and later
        if ( ((DWORD)(HIBYTE(LOWORD(dwVersion))) >= 10) )
        {
          // Define _WIN32_WINNT > 0x0400
          // to compile
          INPUT input[2] = {0};
          input[0].type = input[1].type = INPUT_KEYBOARD;
          input[0].ki.wVk = input[1].ki.wVk = VKey;
          input[1].ki.dwFlags = KEYEVENTF_KEYUP;
          ::SendInput(sizeof(input) / sizeof(INPUT), input, sizeof(INPUT));
        }
        // Win95
        else
        {
          KEYBOARDSTATE_t KeyboardState;
          NumState = GetKeyState(VK_NUMLOCK) & 1 ? true : false;
          GetKeyboardState(&KeyboardState[0]);
          if (NumState)
            KeyboardState[VK_NUMLOCK] &= ~1;
          else
            KeyboardState[VK_NUMLOCK] |= 1;

          SetKeyboardState(&KeyboardState[0]);
        }
      }
    }
    return;
  }

  // Get scancode
  ScanCode = LOBYTE(::MapVirtualKey(VKey, 0));

  // Send keys
  for (Cnt=1; Cnt<=NumTimes; Cnt++)
  {
    // Carry needed delay ?
    if (bDelay)
      CarryDelay();

    KeyboardEvent(VKey, ScanCode, IsVkExtended(VKey) ? KEYEVENTF_EXTENDEDKEY : 0);
    if (GenUpMsg)
      KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP);
  }
}
Example #10
0
File: Vcc.c Project: vcc6809/VCC
// The Window Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	unsigned int x,y;
	unsigned char kb_char; 
	kb_char=(unsigned char)wParam;
	static unsigned char OEMscan=0;
	static char ascii=0;
	static RECT ClientSize;
	static unsigned long Width,Height;

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			// Added for Dynamic menu system
			if ( (wmId >=ID_SDYNAMENU) & (wmId <=ID_EDYNAMENU) )
			{
				DynamicMenuActivated (wmId - ID_SDYNAMENU);	//Calls to the loaded DLL so it can do the right thing
				break;
			}

			switch (wmId)
			{	
				case IDM_HELP_ABOUT:
					DialogBox(EmuState.WindowInstance, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				    break;

				case ID_CONFIGURE_OPTIONS:
					
					if (EmuState.ConfigDialog==NULL)
					{
						EmuState.ConfigDialog = CreateDialog (NULL,(LPCTSTR)IDD_TCONFIG,EmuState.WindowHandle,(DLGPROC) Config) ;
						ShowWindow (EmuState.ConfigDialog, SW_SHOWNORMAL) ;
					}
				//	DialogBox(EmuState.WindowInstance, (LPCTSTR)IDD_TCONFIG, hWnd, (DLGPROC)Config);
				    break;


				case IDOK:
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					break;

				case ID_FILE_EXIT:
					BinaryRunning=0;
					break;

				case ID_FILE_RESET:
					if (EmuState.EmulationRunning)
						EmuState.ResetPending=2;
					break;

				case ID_FILE_RUN:
					EmuState.EmulationRunning=TRUE;
					InvalidateBoarder();
					break;

				case ID_FILE_RESET_SFT:
					if (EmuState.EmulationRunning)
						EmuState.ResetPending=1;
					break;

				case ID_FILE_LOAD:
					LoadIniFile();
					EmuState.ResetPending=2;
					SetClockSpeed(1); //Default clock speed .89 MHZ	
					break;

				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;

//		case WM_CREATE:
//				
//			break;
//		case WM_SETFOCUS:
//			Set8BitPalette();
//			break;

		case WM_CLOSE:
			BinaryRunning=0;
			break;

		case WM_CHAR:
//			OEMscan=(unsigned char)((lParam & 0xFF0000)>>16);
//			ascii=kb_char;
//			sprintf(ttbuff,"Getting REAL CHAR %i",ascii);
//			WriteLine ( ttbuff);
//			KeyboardEvent(kb_char,OEMscan,1); //Capture ascii value for scancode
			return 0;
			break;

		case WM_KEYUP:
		case WM_SYSKEYUP:
			OEMscan=(unsigned char)((lParam & 0xFF0000)>>16);
			KeyboardEvent(kb_char,OEMscan,0);
			return 0;
		break;

		case WM_KEYDOWN: 
		case WM_SYSKEYDOWN:
			OEMscan=(unsigned char)((lParam & 0xFF0000)>>16);

			switch (OEMscan)
			{
				case 61:	//F3

				break;
				case 62:	//F4

				break;

				case 63:	//F5
					if (EmuState.EmulationRunning)
						EmuState.ResetPending=1;
				break;

				case 64:	//F6
					SetMonitorType(!SetMonitorType(QUERY));
				break;

	//			case 65:	//F7
	//				SetArtifacts(!SetArtifacts(QUERY));
	//			break;

				case 66:	//F8
					SetSpeedThrottle(!SetSpeedThrottle(QUERY));
				break;

				case 67:	//F9
					EmuState.EmulationRunning=!EmuState.EmulationRunning;
					if (EmuState.EmulationRunning)
						EmuState.ResetPending=2;
					else
						SetStatusBarText("",&EmuState);
				break;

				case 68:	//F10
					SetInfoBand(!SetInfoBand(QUERY));
					InvalidateBoarder();
				break;
				
				case 87:	//F11
				if (FlagEmuStop==TH_RUNNING)
				{
					FlagEmuStop=TH_REQWAIT;
					EmuState.FullScreen=!EmuState.FullScreen;
				}
		
				break;

	//			case 88:	//F12
	//				CpuDump();
	//				break;

				default:
					if (EmuState.EmulationRunning)
						KeyboardEvent(kb_char,OEMscan,2);		
					break;
			}
			return 0;
		break;

		case WM_LBUTTONDOWN:  //0 = Left 1=right
			SetButtonStatus(0,1);
			break;

		case WM_LBUTTONUP:
			SetButtonStatus(0,0);
			break;

		case WM_RBUTTONDOWN:
			SetButtonStatus(1,1);
			break;

		case WM_RBUTTONUP:
			SetButtonStatus(1,0);
			break;

		case WM_MOUSEMOVE:
			if (EmuState.EmulationRunning)
			{
				x = LOWORD( lParam ) ;
				y = HIWORD( lParam ) ;
				GetClientRect(EmuState.WindowHandle,&ClientSize);
				x/=((ClientSize.right-ClientSize.left)>>6);
				y/=(((ClientSize.bottom-ClientSize.top)-20)>>6);
				joystick(x,y);
			}
			return(0);
			break;
//		default:
//			return DefWindowProc(hWnd, message, wParam, lParam);
   }
Example #11
0
			Keyboard( double const xDebounceTicks = 18000000.0 )
				: mM( )
				, mQuit( )
				, mCallbacks( )
				, mInitialized( false )
				, mKeyboardListener( [ & ] ( int64_t const xSleepIntervalNs ) -> uint32_t
		  		{
			                bool pressedLastTime[ SDL_NUM_SCANCODES ];

					for ( uint16_t ii = 0; ii < SDL_NUM_SCANCODES; ++ii )
					{
						pressedLastTime [ ii ] = false;
					}

					double continueDebounceAccum = 0.0;

					Stopwatch t;

					while ( !mQuit.isSet( ) )
					{
						if ( xSleepIntervalNs > 0 )
						{
							sleep::ns( xSleepIntervalNs );
						}

						const Uint8 * state = SDL_GetKeyboardState( NULL );

		        	                for ( uint16_t ii = 0; ii < SDL_NUM_SCANCODES; ++ii )
	        	        	        {
							eKeyState keyState = eKeyState_None;

							auto runCallbacks = [&]()
							{
								mM.run([&]( )
								{
									for ( auto callback : mCallbacks )
									{
										callback( KeyboardEvent( keyState, ii, state ) );
									}
								});
							};

		        	                        if ( state[ ii ] && !pressedLastTime[ ii ] )
		                	                {
								keyState = eKeyState_Down;
								t.startMs( );
			                                }
							else if ( state[ ii ] && pressedLastTime[ ii ] )
							{
								continueDebounceAccum += t.stop( );

								if ( continueDebounceAccum > mDebounceTicks )
								{
									keyState = eKeyState_Continue;
									continueDebounceAccum = 0;
									t.startMs( );
								}
							}
		        	                        else if ( !state[ ii ] && pressedLastTime[ ii ] )
		                	                {
								keyState = eKeyState_Up;
			                                }

							if ( keyState != eKeyState_None )
							{
								runCallbacks( );
							}

			                                pressedLastTime[ ii ] = state[ ii ];
						}
					}
				})
				, mDebounceTicks( xDebounceTicks )
			{
				SISULOG( "In Keyboard Ctor" );
			}
Example #12
0
 void OisInputListener::repeatKey(KeyboardEvent::Key key, unsigned int character)
 {
   mEventRedirect->fireEvent(KeyboardEvent(KeyboardEvent::KEY_DOWN, key, character, getModifiersState()));
 }