Friday, 29 May 2020

Virtual Keyboad


Imports System.Net
Imports System.Threading

Public Class Form1
    Declare Function Wow64DisableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
    Declare Function Wow64EnableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean
    Private osk As String = "C:\Windows\System32\osk.exe"
    Private pOSK As Process = Nothing
    Private Const _ENGLISH As String = "ENGL"
    Private Const _AFRI As String = "AFRI"


    Dim Online_Status As Boolean = vbFalse
    'Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'If My.Computer.Network.IsAvailable Then
        '    Try
        '        Dim DNSTest As IPHostEntry = Dns.GetHostEntry("google.com")
        '        If DNSTest.AddressList.Length > 0 Then
        '            Online_Status = True
        '            Detect_Joe_Network()
        '        Else : Online_Status = False

        '        End If

        '    Catch ex As System.Net.Sockets.SocketException

        '        Online_Status = False

        '    End Try
        'End If
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        'Process.Start("C:\Windows\System32\OSK.EXE")
        If CheckBox1.Checked = True Then
            Keyboard_Show()
            'SendSystemKeys "{Ctrl+Esc}"
            'SendKeys.Send("{ }")

            'SendKeys.SendWait("{}")
            'Thread.Sleep(10)
            'SendKeys.SendWait("{ }")

            'SendKeys.SendWait("{Win} + { }")
            'SendKeys.SendWait("{ }")
        Else
            Keyboard_Hide()
        End If

        Dim ProcID As Integer
        ' Start the Notepad application, and store the process id.
        ProcID = Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus)
        ' Activate the Notepad application.
        AppActivate(ProcID)
        ' Send the keystrokes to the Notepad application.
        My.Computer.Keyboard.SendKeys("I ", True)
        My.Computer.Keyboard.SendKeys("♥", True)
        My.Computer.Keyboard.SendKeys(" Visual Basic!", True)

        ''We wll use the case statement to inspect the sender object's .Tag property.

        'Select Case sender.Tag
        '    Case _AFRI   'If the Tag contains the word "AFRi"

        '        'Loop through all the installed languages on this system.
        '        For Each Lng As InputLanguage In _
        '           InputLanguage.InstalledInputLanguages

        '            'If there exists a language whose DisplayName has the
        '            'word "AFRI" in it

        '            If Lng.Culture.DisplayName.ToUpper.StartsWith(_AFRI) Then

        '                'Change current input language to that

        '                InputLanguage.CurrentInputLanguage = Lng

        '                'Exit for - coz we have found our language and no need
        '                'to go through the rest of the loop

        '                Exit For

        '            End If

        '        Next

        '    Case _ENGLISH   'If the Tag contains the word "ENGL"

        '        'Loop through all the installed languages on this system

        '        For Each Lng As InputLanguage In _
        '          InputLanguage.InstalledInputLanguages

        '            'If there exists a language whose DisplayName has the
        '            'word "ENGL" in it

        '            If Lng.Culture.DisplayName.ToUpper.StartsWith(_ENGLISH) Then

        '                'Change current input language to that

        '                InputLanguage.CurrentInputLanguage = Lng

        '                'Exit for - coz we have found our language and no need
        '                'to go through the rest of the loop

        '                Exit For

        '            End If

        '        Next

        'End Select

    End Sub
    Public Sub Keyboard_Show()
        'An instance is running => Dan wordt pOSK het bestaande proces
        For Each pkiller As Process In Process.GetProcesses
            If String.Compare(pkiller.ProcessName, "osk", True) = 0 Then pOSK = pkiller
        Next

        'If no instance of OSK is running than create one depending on 32/64 bit
        For Each pkiller As Process In Process.GetProcesses
            If Not (String.Compare(pkiller.ProcessName, "osk", True) = 0) And (pOSK Is Nothing) Then

                Dim old As Long
                If Environment.Is64BitOperatingSystem Then
                    '64 Bit
                    If Wow64DisableWow64FsRedirection(old) Then
                        pOSK = Process.Start(osk)
                        Wow64EnableWow64FsRedirection(old)
                    End If
                Else
                    '32 Bit
                    pOSK = Process.Start(osk)
                End If
                Exit For
            End If
        Next
    End Sub


    Public Sub Keyboard_Hide()
        For Each pkiller As Process In Process.GetProcesses
            If String.Compare(pkiller.ProcessName, "osk", True) = 0 And Not (pOSK Is Nothing) Then

                ' Terminate process
                pOSK.Kill()
                Exit For
            End If
        Next

        'Wait untill proces is really terminated
        For intStap As Integer = 1 To 10
            For Each pkiller As Process In Process.GetProcesses
                If String.Compare(pkiller.ProcessName, "osk", True) = 0 Then
                    Thread.Sleep(1000)
                Else
                    pOSK = Nothing
                    Exit For
                End If
            Next
        Next intStap
    End Sub

    Private Sub TextBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseClick
        Keyboard_Show()
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

Tuesday, 17 March 2020

How to read a specific line from a text file in VB


        Dim fileReader As String
        Dim fileReader1 As String
        Dim fileReader2 As String
        Dim fileReader3 As String

        fileReader = My.Computer.FileSystem.ReadAllText("C:\Temp\ConnectionStr.txt")
        fileReader1 = File.ReadAllLines("C:\Temp\ConnectionStr.txt").ElementAt(0).ToString
        fileReader2 = File.ReadAllLines("C:\Temp\ConnectionStr.txt").ElementAt(1).ToString
        fileReader3 = File.ReadAllLines("C:\Temp\ConnectionStr.txt").ElementAt(2).ToString

        MsgBox(fileReader)

Tuesday, 25 February 2020

Rolling up Multiple Rows into a Single Row (STUFF)

SELECT 
   SS.SEC_NAME,
   STUFF((SELECT '; ' + US.USR_NAME 
          FROM USRS US
          WHERE US.SEC_ID = SS.SEC_ID
          ORDER BY USR_NAME
          FOR XML PATH('')), 1, 1, '') [SECTORS/USERS]
FROM SALES_SECTORS SS
GROUP BY SS.SEC_ID, SS.SEC_NAME
ORDER BY 1