标签: keyboard-events

以编程方式发送键盘事件不会将它们分派到输入中

我将以编程方式生成的键盘事件发送到文档。我希望当前聚焦的输入元素能够显示它们,但事实并非如此。事件是使用以下函数从字符串生成的:

const simulateKeyPress = keys => {
  keys.split('').forEach(theKey => {
    const e = new window.KeyboardEvent('keypress', {
      bubbles: true,
      key: theKey,
      keyCode: theKey.charCodeAt(0),
      charCode: theKey.charCodeAt(0),
    })
    document.dispatchEvent(e)
  })
}
Run Code Online (Sandbox Code Playgroud)

如果我将 EventListener 添加到文档中,它将接收所有事件。然而,他们的isTrusted标志设置为 false,这可能是问题所在吗?

javascript input keyboard-events

3
推荐指数
1
解决办法
3990
查看次数

C# 监听键盘组合

我想编写简单的代码program,在某些地方发送我的用户和密码,例如当我想登录网站时,我发现了这个项目正在听键盘。

所以我有这个功能:

private void HookManager_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{

}

private void HookManager_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{

}

private void HookManager_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{

}
Run Code Online (Sandbox Code Playgroud)

例如,当我按下 键时,a我会得到这样的结果:

int value = e.KeyValue; // 65
Keys key = e.KeyCode;   // A
Run Code Online (Sandbox Code Playgroud)

所以我想知道如何捕获特定的keyboard combination而不是仅一个key的例子Ctrl + l

c# keyboard-events winforms

3
推荐指数
1
解决办法
2402
查看次数

通过KeyboardEvent.code找出KeyboardEvent.key

KeyboardEvent 有 2 个属性:

如何在没有事件本身的情况下获得key拥有?code所以我只有code事件之外的值,并且想知道与之key相关的内容。

javascript keycode keyboard-events

3
推荐指数
1
解决办法
1101
查看次数

PHP中的键盘输入

我试图用键盘输入控制PHP的东西.我目前检测击键的方式是:

 function read() {
    $fp1=fopen("/dev/stdin", "r");
    $input=fgets($fp1, 255);
    fclose($fp1);

    return $input;
}
print("What is your first name? ");
    $first_name = read();
Run Code Online (Sandbox Code Playgroud)

问题在于它没有读取"实时"击键.我不知道使用这种方法是否可行,我想这也不是最有效的方法.我的问题是1)如果这是一个很好的方法,那么我怎么能让它工作,这样当你在页面上键入时,它将捕获击键,2)如果这是一个不好的方法,我怎样才能更好地实现它(可能使用ajax或其他东西)?

编辑:我使用PHP作为网页,而不是命令行.

php keyboard-events

2
推荐指数
2
解决办法
3万
查看次数

jQuery兼容HOVER和FOCUS(鼠标和键盘)

我正在构建一个大型菜单,我希望能够通过悬停(使用鼠标)和焦点(例如通过键盘对其进行跳转)来触发菜单.

这就是我现在正在做的事情:

$(".megaMenu-trigger").focus(function (){$(this).hover()});
$(".megaMenu-trigger").hover(function(){
    // do the stuff
});
Run Code Online (Sandbox Code Playgroud)

这是有效的,但我想知道这是否是一起处理键盘和鼠标交互的理想方式.

jquery hover keyboard-events

2
推荐指数
1
解决办法
1万
查看次数

模拟退格按钮在c#中使用null ActiveSource

背景:我们在触摸屏信息亭上使用屏幕键盘,允许用户输入文字.退格按钮失败,因为System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource变为null.

代码上下文:

if (System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource != null)
{
    System.Windows.Input.KeyEventArgs ke = 
        new System.Windows.Input.KeyEventArgs(
            System.Windows.Input.Keyboard.PrimaryDevice, 
            System.Windows.Input.Keyboard.PrimaryDevice.ActiveSource,
            0,
            System.Windows.Input.Key.Back);
    ke.RoutedEvent = UIElement.KeyDownEvent;
    System.Windows.Input.InputManager.Current.ProcessInput(ke);
}
else
{
    Console.Out.WriteLine("Problemo");
}
Run Code Online (Sandbox Code Playgroud)

我不能使用具有null ActiveSource的KeyEventArgs,并且System.Windows.Forms.SendKeys.SendWait("{BACKSPACE}")也不起作用.

c# keyboard-events uikeyboard

2
推荐指数
1
解决办法
3427
查看次数

Silverlight - 按钮控制选项卡停两次神秘

我正在调试一个大的Silverlight应用程序,我发现在每个表单上所有按钮控件都会在进入下一个控件之前接收选项卡焦点两次.我不能在一个简单的hello world应用程序中重现这种行为.有趣的是,这个问题在HyperlinkBut​​ton控件上不会以相同的形式出现,只有Button.知道是什么会导致这个,或者有些事情可以帮助我找出原因吗?

提前致谢.

[编辑]

如果我将IsTabStop属性设置为false,那么它只会在按钮上标记一次.我不愿意使用它作为修复,因为我真的想知道问题的根源是什么.

我已经将问题跟踪到我们在资源文件中使用的Implicit按钮样式.我真的想知道为什么这个XAML会导致这种情况发生.

隐式按钮样式XAML

<Style TargetType="Button" x:Key="DefaultButtonStyle">
    <Setter Property="Background" Value="{StaticResource NormalBrush}"/>
    <Setter Property="Foreground" Value="{StaticResource TextContentBrush}"/>
    <Setter Property="FontFamily" Value="{StaticResource ContentFontFamily}"/>
    <Setter Property="FontSize" Value="{StaticResource ContentFontSize}"/>
    <Setter Property="Padding" Value="3"/>
        <Setter Property="Padding" Value="10,3,10,3" />
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
    <Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="grid" RenderTransformOrigin="0.5,0.5">
    <Grid.RenderTransform>
        <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
        </TransformGroup>
    </Grid.RenderTransform>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <VisualStateGroup.Transitions>
                <VisualTransition From="MouseOver" GeneratedDuration="0:0:0.1" To="Pressed">
                    <VisualTransition.GeneratedEasingFunction>
                        <ExponentialEase EasingMode="EaseIn" Exponent="-2"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
                <VisualTransition From="Pressed" GeneratedDuration="0:0:0.1" To="MouseOver">
                    <VisualTransition.GeneratedEasingFunction>
                        <ExponentialEase EasingMode="EaseOut" Exponent="0"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition> …
Run Code Online (Sandbox Code Playgroud)

silverlight tabs keyboard-events

2
推荐指数
1
解决办法
1586
查看次数

3键键盘快捷键

我需要帮助在我的Java程序中创建键盘快捷键.从下面的代码中可以看出,我需要一个键盘快捷键Ctrl+ + T正常工作并打印"test",但快捷键Ctrl+ Shift+ T没有"test2"按预期打印,没有任何反应:

KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(
    new KeyEventDispatcher() {
        public boolean dispatchKeyEvent(KeyEvent e) {
            switch (e.getID()) {
                case KeyEvent.KEY_PRESSED:
                    if (e.getKeyCode() == java.awt.event.KeyEvent.VK_T && 
                        e.getModifiers() == java.awt.event.InputEvent.CTRL_MASK) {
                        System.out.print("test");   
                    } else if (e.getKeyCode() == java.awt.event.KeyEvent.VK_R && 
                               e.getModifiers() == java.awt.event.InputEvent.CTRL_MASK &&
                               e.getModifiers() == java.awt.event.InputEvent.SHIFT_MASK) {
                        System.out.print("test2");  
                    }       
                break;
            }
            return true;
        }
    }
);
Run Code Online (Sandbox Code Playgroud)

java awt keyboard-events

2
推荐指数
1
解决办法
884
查看次数

JavaFX TextField如何防止键在keypressed事件中输入

我需要检测小键盘按键来做一些事情.这是代码:

textField.setOnKeyPressed(new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
                if(event.getCode().isKeypadKey()) {
                    //do stuff here...
                    event.consume();
                }
            }
        });
Run Code Online (Sandbox Code Playgroud)

让我们说用户在小键盘上按'2',虽然事件被消耗,但是字符串'2'将出现在文本字段中.但我不想那样.任何想法如何防止这种情况?

更有意思的是,如果我抛出一个虚拟异常而不是消耗该事件,它将阻止keytyped事件.

events javafx event-handling keyboard-events textfield

2
推荐指数
1
解决办法
4854
查看次数

滚动时在textview中关闭键盘

我是IOS的新手,我尝试了很多,但在用户触摸任何textview键盘时滚动时仍然失败,显示返回不起作用.

我的输出屏幕截图:

盯着页面和键盘出现页面

keyboard-events textview ios

2
推荐指数
1
解决办法
429
查看次数