Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Simulate Key Press
Author:Arkon
Category:Win32API
File Size:~ 1.50 KB
Uploaded at:27-Nov-02 03:28:46 pm
Description:
  Simulate key press for a macro system or whatever.
  
Sending key pressings.

KEYBDINPUT ki;
ki.wVk = VK_RETURN;
ki.wScan = MapVirtualKeyEx(VK_RETURN, 0, GetKeyboardLayout(0));
ki.dwFlags = KEYEVENTF_EXTENDEDKEY; // or KEYEVENTF_KEYUP, one of those must work :)
ki.time = 0;
ki.dwExtraInfo = 0;
INPUT ipEvent;
ipEvent.type = INPUT_KEYBOARD;
ipEvent.ki = ki;
UINT nNumEvents = SendInput(1, &ipEvent, sizeof(INPUT));

BTW-You can get the window HWND, and then 
SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0);
SendMessage(hWnd, WM_KEYUP, VK_RETURN, 0);


Send ALT+SPACE to current focused window:
 keybd_event(VK_MENU, 0, 0, 0);
 keybd_event(VK_SPACE, 0, 0, 0);
 keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
 keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);


This is an example for console window:
Sends "CLS" and then ENTER.. Guess what it does
 char sc = 0;

 sc = MapVirtualKey(/*VK_C*/0x43, 0);
 SendMessage(hWnd, WM_KEYDOWN, sc, 1 | (1 << 30) | (sc << 16));
 SendMessage(hWnd, WM_KEYUP, sc, 1 | (3 << 30) | (sc << 16));

 sc = MapVirtualKey(/*VK_L*/0x4c, 0);
 SendMessage(hWnd, WM_KEYDOWN, sc, 1 | (1 << 30) | (sc << 16));
 SendMessage(hWnd, WM_KEYUP, sc, 1 | (3 << 30) | (sc << 16));

 sc = MapVirtualKey(/*VK_S*/0x53, 0);
 SendMessage(hWnd, WM_KEYDOWN, sc, 1 | (1 << 30) | (sc << 16));
 SendMessage(hWnd, WM_KEYUP, sc, 1 | (3 << 30) | (sc << 16));

 sc = MapVirtualKey(VK_RETURN, 0);
 SendMessage(hWnd, WM_KEYDOWN, sc, 1 | (1 << 30) | (sc << 16));
 SendMessage(hWnd, WM_KEYUP, sc, 1 | (3 << 30) | (sc << 16));

(Did the target window) Get it?
=0){ mysqli_data_seek($res,$row); $resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res); if (isset($resrow[$col])){ return $resrow[$col]; } } return false; } function ViewComments($pt, $pid, $topic, $conn) { $res = mysqli_query($conn, "SELECT ThreadID FROM CommentThreads WHERE ParentType='$pt' AND ParentID='$pid'") or die("type+id not found"); if (mysqli_num_rows($res) == 0) { echo "\r\n"; // no comments for this thread, just let the user enter one. echo ""; echo ""; echo "
User Contributed Comments(None)
"; displaySubmissionForm($pt, $pid, "", "", "", $topic); echo "
"; return; } $threadid = mysqli_result($res, 0); $res = mysqli_query($conn, "SELECT * FROM Comments WHERE ThreadID='$threadid' ORDER BY Date ASC") or die("no entries"); $colsel = 0; $index = 0; $bgcolors = Array(0 => "#5d88bb", 1 => "#6699dd"); $comments_count = mysqli_num_rows($res); echo ""; if ($comments_count != 0) { echo ""; echo ""; } //comments exist end if echo "
User Contributed Comments(" .$comments_count .")
\r\n"; while($comment = mysqli_fetch_array($res)) { $index = $index + 1; // Point to last inserted comment... if ($index == $comments_count) echo "\r\n"; $submitter = $comment[Name]; // Add email if exists if (strlen($comment[EMail])) { $submitter = "$submitter"; } echo ""; $colsel = ($colsel + 1) & 1; } echo "
 [" .strval($index) ."] " .$submitter ." | " .$comment[Date] ."

" .$comment[Comment] ."
"; displaySubmissionForm($pt, $pid, "", "", "", $topic); echo "
"; } return; function displaySubmissionForm($pt, $pid, $comment, $name, $email, $topic) { //if (strlen($comment) == 0) $comment = ""; if (strlen($name) != 0) $name = "value=\"" .$name ."\""; if (strlen($email) != 0) $email = "value=\"" .$email ."\""; print << NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
END; } ?>