none
Communication between Music Software and Visual Studio

    Question

  • Hello, i'm trying to built an application that can communicate with a Music Editing software, the problem born when i use the command "SendKeys.send("{w}")"  'cause executing it the Music Editing software should reproduce a sample sound associated with the "w" key on keyboard, but nothing happen. Meanwhile if i use the real Keyboard or the virtual one of Windows 10 all work fine.

    Somebody could help me? Thanks a lot!

    Sunday, March 12, 2017 11:50 AM

All replies

  •  Does the music editing program have the keyboard focus when the key is sent,  meaning is it the foreground window when your application sends the key?

    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Sunday, March 12, 2017 12:13 PM
    Sunday, March 12, 2017 12:12 PM
  • Yes, for example if i use "SendKeys.send("{TAB}")" works

    Sunday, March 12, 2017 12:48 PM
  • Might be a good time to ask the maker of the music software how they handle keyboard input.
    Sunday, March 12, 2017 3:41 PM
  • Yes, maybe.By the way if i use the robot.keypress function of javascript it works. There is a similar funcion in C or VB?

    • Edited by andrefun Sunday, March 12, 2017 3:44 PM
    Sunday, March 12, 2017 3:43 PM
  •  What is the name of the editor program?

    If you say it can`t be done then i`ll try it

    Sunday, March 12, 2017 3:47 PM
  • Ableton live Suite

    Sunday, March 12, 2017 4:04 PM
  •  Well,  i see they have a free trial for 30 days and was going to test it but,  at 3GB of required hard drive space for the install,  i am not going to install all that just to test it.

     If you are sending more than one key in a row,  maybe try using SendKeys.SendWait instead.

     You can also try the below method but,  if you are absolutely sure the Ableton program window was focused before you tried using SendKeys to send a "w",  then my guess is that this probably wont work either.  You will need to change the process name from "Notepad" to the process name of the Ableton process.

     
    Imports System.Runtime.InteropServices
    
    Public Class Form1
        Private Const KEYEVENTF_KEYDOWN As Integer = &H0
        Private Const KEYEVENTF_KEYUP As Integer = &H2
    
        <DllImport("user32.dll", EntryPoint:="keybd_event")>
        Private Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim p As Process = Process.GetProcessesByName("Notepad").FirstOrDefault
            If p IsNot Nothing Then
                AppActivate(p.Id)
                Threading.Thread.Sleep(200) 'wait a few hundred milliseconds just to make sure the window is activated before sending the key
    
                'SendKeys.Send("{w}")
    
                keybd_event(CByte(Keys.W), 0, KEYEVENTF_KEYDOWN, 0)
                keybd_event(CByte(Keys.W), 0, KEYEVENTF_KEYUP, 0)
            End If
        End Sub
    End Class
    

     They may be using a special way of handling the keys but,  that is usually only done with games to stop people from cheating and it does not seem likely with an app like this.


    If you say it can`t be done then i`ll try it

    Sunday, March 12, 2017 4:55 PM
  • Not working...
    But why with the robot.Keypress function of java, works fine? I can't understand it
    • Edited by andrefun Sunday, March 12, 2017 5:09 PM
    Sunday, March 12, 2017 5:06 PM
  • Not working...
    But why with the robot.Keypress function of java, works fine? I can't understand it

     I am not sure what api functions the java method uses internally behind the scenes so,  i can`t really say.

     There is also the chance that the editor is running with higher privileges than your application.  I have seen that stop apps from sending keys to specific programs on newer OS`s.  Try running Visual Studio with administrator privileges by right clicking the VS launcher shortcut and choose "Run as Administrator".  That is required sometimes even if you are signed in as an administrator.

     You can also right click your application`s compiled exe file and run it as an administrator the same way.


    If you say it can`t be done then i`ll try it

    Sunday, March 12, 2017 5:28 PM
  • Not working...
    But why with the robot.Keypress function of java, works fine? I can't understand it

     I am not sure what api functions the java method uses internally behind the scenes so,  i can`t really say.

     There is also the chance that the editor is running with higher privileges than your application.  I have seen that stop apps from sending keys to specific programs on newer OS`s.  Try running Visual Studio with administrator privileges by right clicking the VS launcher shortcut and choose "Run as Administrator".  That is required sometimes even if you are signed in as an administrator.

     You can also right click your application`s compiled exe file and run it as an administrator the same way.


    If you say it can`t be done then i`ll try it


    Already did it with the exe file, and if it was that the problem, also the "SendKeys.send("{TAB}")" should not work right?
    Sunday, March 12, 2017 5:30 PM
  • Already did it with the exe file, and if it was that the problem, also the "SendKeys.send("{TAB}")" should not work right?

     Not sure.  Knowing that the Tab key is a system command key and "w" is not,  i was just trying to eliminate any possibilities that i have run into before.

     Well,  i guess you can either go back to using java for the application or create a class in java that you can use in your VB.Net application.  I found the links below that suggest you can use java classes in your vb.net applications.  Don`t know what else to suggest other than that without me having to installing the editor program and testing things myself.

    Do you know that you can call Java classes from Visual Basic ??

    Using Java Classes in your .NET Application


    If you say it can`t be done then i`ll try it

    Sunday, March 12, 2017 6:48 PM