The following code will allow you to simulate the keypress of the keyboard.
This function accepts a string to simulate typing them. It will press the Enter key at the end of the simulation. The code will handle pressing of the "Shift" key when needed.
C++ Source code. MFC.
===============
void SendKeypress(CString strText)
{
int len, i;
char c;
len = strText.GetLength();
for (i = 0; i < len; i++) {
c = strText[i];
WORD vkey = VkKeyScan(c);
WORD shift = HIBYTE(vkey);
BYTE scan = MapVirtualKey(vkey, 0);
if (shift) {
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT,0), 0, 0);
}
keybd_event(vkey, scan, 0, 0);
keybd_event(vkey, scan, KEYEVENTF_KEYUP, 0);
if (shift) {
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT,0), KEYEVENTF_KEYUP, 0);
}
}
// Press "Enter"
keybd_event(VK_RETURN, 0x1c, 0 , 0);
keybd_event(VK_RETURN, 0x9c, KEYEVENTF_KEYUP, 0);
}
Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts
Wednesday, December 15, 2010
Simulate clicking of mouse buttons
The following code allows you to simulate clicking of the mouse button programmatically.
It will remember the current cursor position, move to the coordinate to click, perform the click and restore the cursor position.
C++ source code.
===============
void ClickOnPoint(int x, int y)
{
POINT prevPt;
GetCursorPos(&prevPt);
SetCursorPos(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetCursorPos(prevPt.x, prevPt.y);
}
It will remember the current cursor position, move to the coordinate to click, perform the click and restore the cursor position.
C++ source code.
===============
void ClickOnPoint(int x, int y)
{
POINT prevPt;
GetCursorPos(&prevPt);
SetCursorPos(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetCursorPos(prevPt.x, prevPt.y);
}
Check whether a file exist in C++
The following code allows you do check whether a particular file exist.
C++ source code. Using Shell API.
=======
BOOL CheckFileExist(LPCTSTR lpszFullPathName)
{
BOOL bResult = FALSE;
SHFILEINFO shfileinfo;
if (SHGetFileInfo(lpszFullPathName, 0, &shfileinfo, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME) != 0) {
// File Exist
bResult = TRUE;
}
return bResult;
}
C++ source code. Using Shell API.
=======
BOOL CheckFileExist(LPCTSTR lpszFullPathName)
{
BOOL bResult = FALSE;
SHFILEINFO shfileinfo;
if (SHGetFileInfo(lpszFullPathName, 0, &shfileinfo, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME) != 0) {
// File Exist
bResult = TRUE;
}
return bResult;
}
Monday, August 30, 2010
Failed to install Visual Studio 2008 SP1
If your system has Microsoft Office installed, you may encounter problem when installing Visual Studio 2008 SP1.
The log shows the "Visual Web Developer" is causing the error.
Here is a solution that works for me. You can give it a try.
=======
Rename (or Delete) these two registry keys:
HKEY_CLASSES_ROOT\Installer\Products\00002109120000000000000000F01FEC
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109120000000000000000F01FEC
Renaming the directory
C:\Program Files (x86)\Microsoft Web Designer Tools\VWD
To
C:\Program Files (x86)\Microsoft Web Designer Tools\Junk
(source : http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/315c7885-e680-4a83-b6a5-8a2795f596ea )
The log shows the "Visual Web Developer" is causing the error.
Here is a solution that works for me. You can give it a try.
=======
Rename (or Delete) these two registry keys:
HKEY_CLASSES_ROOT\Installer\Products\00002109120000000000000000F01FEC
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\00002109120000000000000000F01FEC
Renaming the directory
C:\Program Files (x86)\Microsoft Web Designer Tools\VWD
To
C:\Program Files (x86)\Microsoft Web Designer Tools\Junk
(source : http://social.msdn.microsoft.com/Forums/en-US/vssetup/thread/315c7885-e680-4a83-b6a5-8a2795f596ea )
Subscribe to:
Posts (Atom)