Jump to content

Send key


Recommended Posts

I have an integer value (being passed as the lParam) that can be used with the windows GetKeyNameText function to return a string that represents the name of a key. How could I use this same integer value to return a code for AutoIt to send the appropriate key through an AutoIt.Send command? I have a feeling I need to call other windows dll functions to return a value that AutoIt could understand (maybe functions to return a VirtualKey, and then an ASCII representation?), and I'm hoping someone here has the experience needed to help out.

C# example code for using the GetKeyNameText function:

using System.Text;
...

[DllImport("user32.dll")]
static extern int GetKeyNameText(int lParam, [Out] StringBuilder lpString, int nSize);

private void KeyName()
{
StringBuilder sb = new StringBuilder();
GetKeyNameText(18677760, sb, 256);
MessageBox.Show(sb.ToString());
}

...

The integer value in my example is 18677760, and returns "Right Ctrl" as the key text. I know you can use AutoIt.Send("{RCTRL}") to send that key, but I'm looking for a way to programmatically have it send a value returned from a windows function so that I'm not dependent on any type of a lookup table. I don't want my code to have to translate it into something AutoIt will understand, since there is probably a lower level value that AutoIt can understand. Another key that you could experiment with is Caps Lock. It has an integer value of 3801088.

I need to be able to take an input of an lParam int value and have AutoIt send the key that the int value corresponds to. I hope someone can help. Thanks a lot! :lmao:

Link to comment
Share on other sites

;~ int GetKeyNameText(        LONG lParam,
;~   LPTSTR lpString,
;~   int nSize
;~ );
$ret = DllCall("user32.dll","int","GetKeyNameText","long",18677760,"str","","int",256)
MsgBox(0,"test","Length = " & $ret[0] & @LF & "Key Name = " & $ret[2])

Welcome to the forum.

Btw this should of been posted in support

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I appologize for posting it in the Developer forum. I wasn't sure if the people in the support area would have the level of experience I thought would be required for this question.

Yes, using the keybd_event sounds exactly like what I need to do. Do you know how I could use it to simulate holding a key down? Similar to AutoIt's {RALT DOWN}? It looks like the function has a simluate key press, then a simulate key release. Do you think using the simulate key press holds down the key until it is released? I'm interested in getting an equivalent result to the following AutoIt code:

AutoIt.Send("{RALT DOWN}")
AutoIt.Send("r")
AutoIt.Send("{RALT UP}"

I really appreciate your help

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...