InputSimulator在调试时工作,但在构建程序时不工作

时间:2017-07-09 15:36:02

标签: vb.net keyboard keystrokes

在我的项目中我正在使用inputsimulator,当visual studio以管理员身份运行时效果很好,但是当我将它构建为.exe时,即使我以管理员身份运行它也不起作用。这是我的代码

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    AutoSaveTimer.Enabled = True

    Try
        System.Threading.Thread.Sleep(50)
        GameConnection.SendKeyTo(Keys.OemSemicolon)
        System.Threading.Thread.Sleep(2000)
        GameConnection.SendKeyTo(Keys.K)
        System.Threading.Thread.Sleep(50)
        GameConnection.SendKeyTo(Keys.Enter)

    Catch AutoSaveExeption As GameException
        If AutoSaveExeption.GameErrorCode = GameError.GAME_ERR_SENDMSG Then
            ' Send message error - connection to Game lost.
            ' 
            MessageBox.Show("cant make a connection.... can't autosave sadly", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            SimConnectionBar.BackColor = Color.Red
        End If
    End Try
End Sub

它会将焦点发送到我指定的窗口,但它不会发送击键

1 个答案:

答案 0 :(得分:0)

在发送任何输入之前尝试使用SetForegroundWindow以确保您的游戏确实具有焦点。在发送输入之前,应该在您的方法中调用SetForegroundWindow。

imports:
        - { resource: parameters.yml }
        - { resource: security.yml }
        - { resource: services.yml }

    # Put parameters here that don't need to change on each machine where the app is deployed
    # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
    parameters:
        locale: en

    framework:
        secret:          "%secret%"
        csrf_protection: ~
        form: ~
        session:
            handler_id: ~
    fos_user:
        db_driver: orm
        firewall_name: main
        user_class: AppBundle\Entity\User
        from_email:
            address: "test@test.com"
            sender_name: "Demo String"
        service:
            mailer: fos_user.mailer.twig_swift

    lexik_jwt_authentication:
        private_key_path: %jwt_private_key_path%
        public_key_path:  %jwt_public_key_path%
        pass_phrase:      %jwt_key_pass_phrase%
        token_ttl:        %jwt_token_ttl%
    nelmio_cors:
        defaults:
            allow_origin:   ["%cors_allow_origin%"]
            allow_methods:  ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
            allow_headers:  ["content-type", "authorization"]
            expose_headers: ["link"]
            max_age:       3600
        paths:
            '^/': ~
    # Doctrine Configuration
    doctrine:
        dbal:
            driver: pdo_mysql
            host: '%database_host%'
            port: '%database_port%'
            dbname: '%database_name%'
            user: '%database_user%'
            password: '%database_password%'
            charset: UTF8
            # if using pdo_sqlite as your database driver:
            #   1. add the path in parameters.yml
            #     e.g. database_path: '%kernel.root_dir%/data/data.db3'
            #   2. Uncomment database_path in parameters.yml.dist
            #   3. Uncomment next line:
            #path: '%database_path%'

        orm:
            auto_generate_proxy_classes: '%kernel.debug%'
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true

    # Swiftmailer Configuration
    swiftmailer:
        transport: '%mailer_transport%'
        host: '%mailer_host%'
        username: '%mailer_user%'
        password: '%mailer_password%'
        spool: { type: memory }
    fos_rest:
        view:
            view_response_listener: 'force'
            formats:
                json: true
        format_listener:
            rules:
                - { path: '^/api', priorities: ['json'], fallback_format: json, prefer_extension: true }
                - { path: '^/', stop: true }
        param_fetcher_listener: true
        body_listener: 
            enabled: true
            array_normalizer:
                service: fos_rest.normalizer.camel_keys
                forms: true
            decoders:
                json: acme.decoder.json
                xml: fos_rest.decoder.xml
        view:
            view_response_listener: 'force'