I am struggling with this code for turning on the monitor. I have set in the Windows 10 control panel the display to turn off after 10 minutes, but I have one voice recognizing app written in VB and I need to wake the screen when I call the application via voice. So is there a code for waking the monitor trough Visual Basic? I searched a long time but I only find some Java code. Thanks and have a great day/night! :)
Asked
Active
Viewed 2,138 times
2
-
There's surely a way to do this via win32 api calls. – RoyalPotato May 21 '16 at 17:14
-
Found it after about 30 seconds: http://www.codeproject.com/Articles/11099/Turn-on-off-monitor – RoyalPotato May 21 '16 at 17:15
-
If you need me to convert it to vb for you, let me know. – RoyalPotato May 21 '16 at 17:16
-
Wow yeah I found that one and I was trying to convert it but I didn't succeed. I think that's on C right? If so I will need some help. :) – Martin May 21 '16 at 17:20
-
1Please take a moment to read [Ask] and take the [Tour] It will save you downvotes in the long run. – Ňɏssa Pøngjǣrdenlarp May 21 '16 at 17:21
-
I converted it to vb.net (it was c#, actually) and it didn't work on windows10, investigating now ;). – RoyalPotato May 21 '16 at 17:23
-
Working on a solution, but I've got to go for now, so I'll come back when I can :). – RoyalPotato May 21 '16 at 17:35
-
Ok, no problem! Thanks. :) – Martin May 21 '16 at 17:41
-
Have you tried [this solution](http://stackoverflow.com/questions/332649/how-do-i-wake-up-my-windows-monitors-once-turned-off-by-power-settings?rq=1) ? It was originally for Win XP but apparently worked on Vista... Maybe it'll do for Win10 – Martin Verjans May 21 '16 at 18:13
-
I tried it but it does not work for Windows 10. I'm using Visual Basic Express 2010 btw. Thanks for the attention! :) – Martin May 21 '16 at 19:54
1 Answers
1
K, so, with the guidance of the article on codeproject, some of the answers given to this question and pinvoke.net, I've got something working. It could be cleaner, but I leave that up to you :). it is your project, after all ;).
Imports System.Runtime.InteropServices
Public Class Monitor
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MONITORPOWER As Integer = &HF170
Private Const HWND_BROADCAST As Integer = &HFFFF
Private Const INPUT_MOUSE As Integer = 0
Private Const MOUSEEVENTF_MOVE As Integer = 1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function SendInput(<[In]()> ByVal nInput As UInt32,<[In](), MarshalAs(UnmanagedType.LPArray, ArraySubtype:=UnmanagedType.Struct, SizeParamindex:=0)> ByVal pInputs() As INPUT, <[In]()> ByVal cbInput As Int32) As UInt32
End Function
Private Structure INPUT
Public type As Integer
Public dx As Integer
Public dy As Integer
Public mouseData As Integer
Public dwFlags As Integer
Public time As Integer
Public dwExtraInfo As IntPtr
End Structure
Public Shared Sub Disable()
SendMessage(New IntPtr(HWND_BROADCAST), WM_SYSCOMMAND, SC_MONITORPOWER, New IntPtr(2))
End Sub
Public Shared Sub Enable()
Dim input = New INPUT()
input.type = INPUT_MOUSE
input.dx = 1
input.dy = 0
input.mouseData = 0
input.dwFlags = MOUSEEVENTF_MOVE
input.time = 0
input.dwExtraInfo = IntPtr.Zero
SendInput(1, {input}, 28)
End Sub
End Class

Community
- 1
- 1

RoyalPotato
- 515
- 4
- 15
-
Thank you sooo much! After about a mount I was trying to convert the Java and C to VB, trying to move the mouse and I succeed in moving the cursor but not waking up the screen! You did it in one hour! Now I will trim it out the code and implement it to my small Arduino voice dashboard application. THANK YOU SO MUCH! :) :) :) – Martin May 21 '16 at 21:47
-
No worries, the native windows API is almost always the answer ;). Sounds like a cool project, too. Maybe I'll be inspiredto wipe the dust off of my arduino and play around with it again :D. – RoyalPotato May 21 '16 at 21:54
-
You can do A LOT of things with an Arduino board and serial communication with VB. You can even control the board trough the Internet via VB. – Martin May 21 '16 at 22:06