Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1680
  • Last Modified:

SendInput - how to ?

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
furmiga
Asked:
furmiga
  • 3
1 Solution
 
Slick812Commented:
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
 
robert_marquardtCommented:
SendInput is about the same as keybd_event.
It only allows to send a sequence uninterupted.
0
 
furmigaAuthor Commented:
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
 
Slick812Commented:
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
 
Slick812Commented:
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now