Solved

SendInput - how to ?

Posted on 2003-10-31
5
1,613 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
  • 3
5 Comments
 
LVL 33

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 33

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 33

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now