-2

How can I automatically send the Enter key in my message box after 3 seconds? For pressing OK in the message box.

 MessageBox.Show("MESSAGE... ") '? AUTO ENTER in Windows AFTER 3 sec. 

Won´t work see below

I've already tried this code, it does not work, do not penalize my points for it! see ! i think this code dont work , because i tested on my vs2017 dont work . CreateObject("WScript.Shell").Popup("Welcome", 1, "Title") Messagebox stay fixed

Perroni
  • 19
  • 7
  • 4
    Possible duplicate of [msgbox that disappears automatically after certain time](https://stackoverflow.com/questions/6509844/msgbox-that-disappears-automatically-after-certain-time) – 41686d6564 stands w. Palestine Jun 25 '18 at 00:41
  • Just create your own messagebox. – F0r3v3r-A-N00b Jun 25 '18 at 00:46
  • Just keep in mind that the issue with using `SendKeys` is that it just sends keystrokes to the active window. If your message box doesn't have focus at the time, the `Enter` key will be directed elsewhere so it will not only not close your message box, but it may have other undesirable effects. – jmcilhinney Jun 25 '18 at 03:08
  • @jmcilhinney I didn't know that. At the top of the docs it say send to an application (I assumed that was my application) but down in Remarks (Always read Remarks!) it explains the active application. Although a Message Box is modal for your application, it is not globally modal so some other app can receive the send keys. Luckily, I haven't tried to use it in years. – Mary Jun 25 '18 at 04:27
  • jmcilhinney i will think about this solution , I really think the solution is this, but how to put it in the same sequence? I know this works, but I can not fit into the same syntax; The staff marked up another post and penalized the points for nothing. I understand that maybe this code resolves SendKeys.Send ("{ENTER}") but needs to be next to the text message. – Perroni Jun 25 '18 at 06:08
  • Ahmed Abdelhameed , wont work – Perroni Jun 25 '18 at 06:09
  • Possible duplicate of msgbox that disappears automatically after certain time – Ahmed Abdelhameed 9 hours ago i think you remove 2 points of me ! :( . not is the same problem , not a solution . Dont work , CreateObject("WScript.Shell").Popup("Welcome", 1, "Title") – Perroni Jun 25 '18 at 10:33
  • jmcilhinney i try put on the same messagebox.show ("text", SendKeys.Send ("{ENTER}") ) but dont accept . i make a newform like a F0r3v3r-A-N00b suggest . Command CreateObject("WScript.Shell").Popup("Welcome", 1, "Title") dont work . – Perroni Jun 25 '18 at 10:36

2 Answers2

0

I solve my problema using this codes. Actually, I managed to solve it in two ways. There goes the first

enter image description here

Code:

Public Class Form1 Private Declare Sub keybd_event Lib "user32" _ (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Byte, ByVal dwExtraInfo As Byte)

Private Const VK_RETURN As Byte = &HD
Private Const KEYEVENTF_KEYDOWN As Byte = &H0
Private Const KEYEVENTF_KEYUP As Byte = &H2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New Threading.Thread(AddressOf closeMsgbox)
    t.Start(3) '3 second delay
    MsgBox("message")

End Sub

Private Sub closeMsgbox(ByVal delay As Object)
    Threading.Thread.Sleep(CInt(delay) * 1000)
    AppActivate(Me.Text)
    keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
    keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
End Sub

End Class

I solved my problem with this ideia too , based on the user idea F0r3v3r-A-N00b, I created a new form window, like a messagebox, I placed an x ​​seconds timer with my SQL write event + the information sending code.

ty F0r3v3r-A-N00b for idea !

PART - 1 , see for details

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


               entrada_log_mensagem.Show()

End Sub

PART - 2 , see for timer details

Private Sub entrada_log_mensagem_Load(sender As Object, e As EventArgs) Handles MyBase.Load PRINCIPAL.Show() Timer.Start() End Sub

Private Sub Timer_Tick(sender As Object, e As EventArgs) Handles Timer.Tick
    Me.Close()
End Sub

I hope I have helped the community with this code as well, because I went through a problem and could not solve it. Ahmed Abdelhameed's suggestion did not really work, but I thank him for his attention. Anyway now everything is working as it should

Thank you again to everyone who could give their time for this.

Perroni
  • 19
  • 7
  • If you want to answer your own question, [that's totally fine](https://stackoverflow.com/help/self-answer). However, you need to copy and paste the code into your answer _as code, not as a screenshot_ and remember to [format it in a code block](https://stackoverflow.com/help/formatting). Read: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – 41686d6564 stands w. Palestine Jun 25 '18 at 07:44
0

you can add timer and but

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    Try
        Timer1.Start()
    Catch ex As Exception
        Timer1.Stop()
    End Try
End Sub



Dim sec As Integer = 0

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    sec += 1
    If sec = 10 Then
        MsgBox("message")
        Timer1.Stop()
        sec = 0
        btnSend_Click(sender, e)
    End If
End Sub
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 20 '22 at 03:52