Sendkey () function

  1. 5 years ago

    27 Oct 2013 Zizki - SLovenia (EU)

    Hi..
    In VB or VBA function exists sendKey (). Is there something in Xojo? Or how can simulate keyboard?

    Thanks

    This should work in windows

    Class Window1
    Inherits Window
    wsh As OleObject
    
    Window1 Control PushButton1:
    Sub Action()
    wsh = new OLEObject("WScript.Shell")
    Dim np as OLEObject
    np = wsh.Run("notepad",1)
    Timer1.Mode = Timer.ModeSingle
    End Sub
    
    Window1 Control Timer1:
    Sub Action()
    wsh.AppActivate("Untitled - Notepad")
    wsh.SendKeys("Hello from Xojo")
    End Sub
    End Class
  2. Norman P

    27 Oct 2013 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    A direct equivalent does not exist.
    What is it you're trying to accomplish with this ?

  3. 27 Oct 2013 Zizki - SLovenia (EU)

    Via the serial port to control the application. I need about 6 keys to control the functions of the program.

  4. Norman P

    27 Oct 2013 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    Don't have all the code IN the events of the various controls

    Write methods that the events in the controls call - then you can control your application by having a serial control simply call the same methods

  5. try: http://www.mbsplugins.eu/RemoteControlPressKey.shtml

  6. 27 Oct 2013 Zizki - SLovenia (EU)

    The application has shortcuts that are controlled by buttons on the keyboard, such as S-> save, O-> Ok ...

    I need to write a program that will receive a string from the serial port into a virtual key press S or O, and the application will respond to these strings passed ... I hope it is easy to understand.

  7. Norman P

    27 Oct 2013 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    Sure
    I just wouldn't do that by "pressing keys"

    Write a method "SaveToFile"
    Then the menu handler for the short cut for Save just called that method
    And if you have a serial object listening & it receives the command to save then it calls the same SaveToFile method as well instead of pressing the button to cause the save to happen

  8. 27 Oct 2013 Zizki - SLovenia (EU)

    It would be easy if the application was written in Xojo. Since it is an older application, there is no other option. The manufacturer offers a similar solution, but it is expensive as it was made ​​of gold :-)

  9. On Mac try AppleScript:

    tell application "System Events"
    	tell application "TextEdit" to activate
    	keystroke "S" using command down
    end tell
  10. Norman P

    27 Oct 2013 Xojo Inc, Pre-Release Testers, Xojo Pro Seeking work. npalardy@great-w...

    Ah so you're not manipulating a program you wrote but another one.
    That wasn't clear.

    Find the Windows Functionality Suite as it has a method that is similar to the VB Sendkeys one
    You can incorporate that into your program & do what you're trying to do

  11. John H

    30 Oct 2013 Pre-Release Testers Answer Planet earth
    Edited 5 years ago

    This should work in windows

    Class Window1
    Inherits Window
    wsh As OleObject
    
    Window1 Control PushButton1:
    Sub Action()
    wsh = new OLEObject("WScript.Shell")
    Dim np as OLEObject
    np = wsh.Run("notepad",1)
    Timer1.Mode = Timer.ModeSingle
    End Sub
    
    Window1 Control Timer1:
    Sub Action()
    wsh.AppActivate("Untitled - Notepad")
    wsh.SendKeys("Hello from Xojo")
    End Sub
    End Class
  12. 3 years ago

    John H

    8 May 2016 Pre-Release Testers Planet earth

    @John H This should work in windows

    Class Window1 Inherits Window wsh As OleObject Window1 Control PushButton1: Sub Action() wsh = new OLEObject("WScript.Shell") Dim np as OLEObject np = wsh.Run("notepad",1) Timer1.Mode = Timer.ModeSingle End Sub Window1 Control Timer1: Sub Action() wsh.AppActivate("Untitled - Notepad") wsh.SendKeys("Hello from Xojo") End Sub End Class

    Make sure the default settings for Time1:
    Timer1.mode = 0 // Off
    Timer1.period = 100

or Sign Up to reply!