Does anyone know how to make the computer press a key without you toughing the keyboard when you click on a button?
Exp: you click a button and the computer presses the print screen key
Printable View
Does anyone know how to make the computer press a key without you toughing the keyboard when you click on a button?
Exp: you click a button and the computer presses the print screen key
Use SendKeys, eg:
SendKeys("{PRTSC}")
You can use the SendKeys function to simulate keystrokes, however you can't use SendKeys to operate the PrintScreen key for any application! If this is what you are trying to achieve, you might have to think about using the clipboard or some other way, if your example was just an example and you need to know about SendKeys, let me know.
tell me more about sendkeys
You can use SendKeys to send key strokes to an application, for example if you were to create a Microsoft Word object and then activated a new document, you could write text to the document like this:
SendKeys "Dear Sir,"
It can be very useful, if you have MSDN help look it up if not let me know what you want to do and I will give you a solution.
You also use the keybd_event API function istead of Sendkeys function.
There are some keys that you can not differenciate such as Left Ctrl, Right Ctrl, Left Shift and Right Shift. For this, you can use DirectInput.
With this code I can detect the Left/Right Shift and Left/Right Control key event
Code:Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_LCONTROL = &HA2
Private Const VK_LSHIFT = &HA0
Private Const VK_RSHIFT = &HA1
Private Const VK_RCONTROL = &HA3
Private Sub Timer1_Timer()
If GetKeyState(VK_LSHIFT) < 0 Then
MsgBox "L_SHIFT"
ElseIf GetKeyState(VK_RSHIFT) < 0 Then
MsgBox "R_SHIFT"
ElseIf GetKeyState(VK_LCONTROL) < 0 Then
MsgBox "L_Ctrl"
ElseIf GetKeyState(VK_RCONTROL) < 0 Then
MsgBox "R_Ctrl"
End If
End Sub