Solved

SendInput - how to ?

Posted on 2003-10-31
5
1,640 Views
Last Modified: 2007-12-19
I want to use the SendInput function to simulate a keystroke ( in this case the key is "1"  normal, not the pad ). Well... some ppl will say "use the keyb_event" but i want to know how to use SendInput on Delphi ! :) and.. this is que question. How to simulate a keypress using the SendInput  function ? Please, i really need to know all steps including the KEYBDINPUT and INPUT members of SendInput.
0
Comment
Question by:furmiga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 34

Accepted Solution

by:
Slick812 earned 200 total points
ID: 9662089
hello furmiga, you might try this code, You will need to set the TInput "type" to INPUT_KEYBOARD for keyboard, and you will not ususually not need to have any Scan code.


procedure TForm1.sbut_SendInputClick(Sender: TObject);
var
Input1: TInput;
begin
Input1.Itype := INPUT_KEYBOARD;
Input1.ki.wVk := $31; // $31 is the VK_1
Input1.ki.wScan := 0;
Input1.ki.dwFlags := 0;
Input1.ki.time := 0;
Input1.ki.dwExtraInfo := 0;
if SendInput(1, Input1, SizeOf(Input1)) = 0 then
  begin
  ShowMessage('Input event was Blocked');
  Exit
  end;
Input1.ki.dwFlags := KEYEVENTF_KEYUP;
SendInput(1, Input1, SizeOf(Input1));
end;
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 9662117
SendInput is about the same as keybd_event.
It only allows to send a sequence uninterupted.
0
 
LVL 7

Author Comment

by:furmiga
ID: 9662130
Okie Slick812 u really solved my problem. Now i can use this ....... function :)

Now... talking about dwflags y i cant use KEYEVENTF_SCANCODE ? I mean, i need this flag cuz there is no other way to send a command to a DXInput app. DirectInput only accept Scan code eventes.... i sow a few C# or C++ apps that uses KEYEVENTF_SCANCODE... Is there anything i can do for the KEYEVENTF_SCANCODE works on Delphi's apps ?

oh btw i am justing keeping this Article oppened cuz i really need this awser :) u already got the points with A grade :) i ll close this topic i a few hours but.... if you or anyone here answer my question i ll be glad :)


Thx man.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 9663689
to get a scan code. . . you could get the  scan code from a WM_KEYDOWN or WM_KEYUP message in the 3 byte of the lParam for a certain key. . I will have to look at some of my references, to see what I can find
0
 
LVL 34

Expert Comment

by:Slick812
ID: 9663769
The scan code is Device Dependent, so different Keyboards will have different scan codes, however, by now there seem to be some "Standard" for the scan codes and certain keys on all keyboards, , , by that may not be the case for all (particulrly NON-English keyboards). . . anyway the scan code for my keyboard "1" charater is 2,  for "2" is 3, , for character "3" is 4, for "4" is 5, , ect. . .
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question