Loduwijk Posted September 16, 2006 Posted September 16, 2006 (edited) I am wondering if there is any way to tell the Send function to send a keystroke for the key specified by a certain keycode, similar to the way you can specify ASCII codes. I am using the AutoIt DLL in VB to make a program that I can use to control any of the computers on my network from any of the other computers on it. I am simply using the main form's KeyDown event to send the keystrokes across the network to the other computer's running instance of the program which will then execute the same keystroke. The KeyDown event obviously specifies the key code to the key pressed. So basically, what I'm looking to do is something like Send("{KEYCODE N}"), where N is the keycode from 0 to 255, so that I can execute a variable keystroke. If there's no way to do this, I'll just have to write a function that takes a keycode and generates the text string required to pass to Send. It would be nice if there's a way to just specify a variable keycode though. Thanks ahead of time. Edited September 16, 2006 by Loduwijk
marfdaman Posted September 16, 2006 Posted September 16, 2006 From the helpfile: Quote To send the ASCII value A (same as pressing ALT+065 on the numeric keypad) Send("{ASC 065}")(When using 2 digit ASCII codes you must use a leading 0, otherwise an obsolete 437 code page is used). Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Loduwijk Posted September 16, 2006 Author Posted September 16, 2006 Thank you, but I am looking to use key codes, not ascii codes. I said that, but perhaps the way I said so wasn't clear enough. Where an ASCII code is the way a character is represented in memory on on disk, a key code is the representation of the key you press to perform a certain action. For example, the ASCII code for "a" is 97, but the key code 97 is for the "1" on the numpad. Every key on the keyboard has assigned its own keycode, even the keys which have nothing to do with ASCII, such as the arrow keys (Left, up, right, down being key codes 37, 38, 39 and 40, respectively, whereas those ASCII numbers are for &, ', ( and )). I hope that clears it up, though I am doubting now that AutoIt supports key codes, which would be odd since key codes have more to do with sending window messages than ASCII does.
Loduwijk Posted September 17, 2006 Author Posted September 17, 2006 (edited) I decided to just go ahead and make a function to convert a keycode into an appropriate text string for use with Send. I thought I'd post it here in case anyone else searches the forum for posts on the same topic like I did before I posted. I might as well save them some time. This is Visual Basic code to convert a keyboard keycode into a text string representative of AutoIt's Send function's required text string. I left shift, alt and ctrl out on purpose because I handle them seperately in my program, but you can easily add them in too. The key codes for shift, ctrl and alt, respectively, are 16, 17 and 18. (There, I just editted that code to use a case structure instead. 'Twas silly of me to just use a huge tree of if statements.) expandcollapse popupPrivate Function KeyCode2Char(KeyCode As Integer) As String Select Case KeyCode Case 8 KeyCode2Char = "{backspace}" Case 9 KeyCode2Char = "{tab}" Case 13 KeyCode2Char = "{enter}" Case 20 KeyCode2Char = "{capslock toggle}" Case 32 KeyCode2Char = "{space}" Case 33 KeyCode2Char = "{pgup}" Case 34 KeyCode2Char = "{pgdn}" Case 35 KeyCode2Char = "{end}" Case 36 KeyCode2Char = "{home}" Case 37 KeyCode2Char = "{left}" Case 38 KeyCode2Char = "{up}" Case 39 KeyCode2Char = "{right}" Case 40 KeyCode2Char = "{down}" Case 45 KeyCode2Char = "{ins}" Case 46 KeyCode2Char = "{del}" Case 106 KeyCode2Char = "{numpadmult}" Case 107 KeyCode2Char = "{numpadadd}" Case 109 KeyCode2Char = "{numpadsub}" Case 110 KeyCode2Char = "{numpaddot}" Case 111 KeyCode2Char = "{numpaddiv}" Case 144 KeyCode2Char = "{numlock toggle}" Case 145 KeyCode2Char = "{scrolllock toggle}" Case 186 KeyCode2Char = ";" Case 187 KeyCode2Char = "=" Case 188 KeyCode2Char = "," Case 189 KeyCode2Char = "-" Case 190 KeyCode2Char = "." Case 191 KeyCode2Char = "/" Case 192 KeyCode2Char = "`" Case 219 KeyCode2Char = "{" Case 220 KeyCode2Char = "\" Case 221 KeyCode2Char = "}" Case 222 KeyCode2Char = "'" Case Else If KeyCode >= 48 And KeyCode <= 57 Then KeyCode2Char = KeyCode - 48 If KeyCode >= 65 And KeyCode <= 90 Then KeyCode2Char = Chr(KeyCode + 32) If KeyCode >= 96 And KeyCode <= 105 Then KeyCode2Char = "{numpad" & KeyCode - 96 & "}" If KeyCode >= 112 And KeyCode <= 123 Then KeyCode2Char = "{F" & KeyCode - 111 & "}" End Select End Function Edited September 17, 2006 by Loduwijk
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now