keyboard-events 相关问题

在键盘输入设备上按下键时触发的事件

输入附件视图在键盘隐藏和显示事件中表现异常

我遇到了InputAccessoryView的奇怪行为,我正在聊天屏幕上工作,我在其中使用了InputAccessoryView,其中我注册了KeyboardWillShow和KeyboardWillHide通知...

回答 3 投票 0

将键盘中断更改为“输入”

我有以下代码: 导入时间 def run_indefinitely(): 而真实: # 无限期运行的代码放在这里 print("无限期运行...") 时间.睡眠(1)...

回答 1 投票 0

在 cdk-virtual-scroll-viewport 中按导航向上/向下按钮时滚动不起作用

我在 mat-autocomplete 中使用 cdk-virtual-scroll-viewport。每当使用鼠标滚动时滚动都可以正常工作,但每当按下 keydown 按钮时滚动就不起作用。 预期行为: 如果焦点转移...

回答 1 投票 0

shift鼠标点击触发

我可以使用触发器触发元素选择器上的单击事件 $('元素选择器').trigger('点击') 是否可以触发shift点击。我的意思是 Shift + 鼠标左键单击。

回答 3 投票 0

如何使我的控件可聚焦?

我有控制 公共类 FocusTestControl :控制 { 公共 FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); } } 这是它的默认样式 <question vote="0"> <p>我有一个控制</p> <pre><code>public class FocusTestControl : Control { public FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); } } </code></pre> <p>这是它的默认样式</p> <pre><code> &lt;Style TargetType=&#34;local:FocusTestControl&#34;&gt; &lt;Setter Property=&#34;Focusable&#34; Value=&#34;True&#34; /&gt; &lt;Setter Property=&#34;Template&#34;&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;Grid&gt; &lt;Border Background=&#34;AliceBlue&#34; /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>我将此控件放在窗口上:</p> <pre><code>&lt;Window x:Class=&#34;MakeWpfControlFocusable.MainWindow&#34; xmlns=&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34; xmlns:local=&#34;clr-namespace:MakeWpfControlFocusable&#34; Title=&#34;MainWindow&#34; Height=&#34;350&#34; Width=&#34;525&#34;&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height=&#34;35&#34; /&gt; &lt;/Grid.RowDefinitions&gt; &lt;local:FocusTestControl /&gt; &lt;StackPanel Grid.Row=&#34;1&#34; Orientation=&#34;Horizontal&#34;&gt; &lt;TextBlock Text=&#34;Focused element: &#34; /&gt; &lt;TextBlock Text=&#34;{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=KeyboardFocusedElement}&#34; /&gt; &lt;TextBox Text=&#34;Text&#34; /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>但是单击控件并不会使其聚焦(我的意思是 KebordFocus)</p> <p>实际上,我的任务是处理 KeyDown 和 KeyUp 事件。但当元素没有键盘焦点时这是不可能的。</p> </question> <answer tick="true" vote="1"> <p>可以通过按 Tab 键盘键来设置键盘焦点。但点击 <pre><code>Control</code></pre> 时并未设置。我已订阅 <pre><code>MouseDown</code></pre> 事件并在处理程序中手动设置焦点。</p> <pre><code>public class FocusTestControl : Control, IInputElement { public FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); MouseDown += FocusTestControl_MouseDown; } void FocusTestControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Keyboard.Focus(this); } } </code></pre> </answer> </body></html>

回答 0 投票 0

Python 键盘库在 Windows 上返回大写和小写,但在 Linux 上仅返回小写

我使用键盘Python库将键盘输入输入到我的应用程序中,我发现了一个奇怪的不规则现象。在Windows上测试时,打印结果显示基于大小写字母...

回答 1 投票 0

有没有办法限制Python的keyboard.add_hotkey()每次按键只触发一次?

导入键盘 def on_c_pressed(): print("C键被按下") Keyboard.add_hotkey('c', on_c_pressed) 目前的情况是,当按下按键时,它会快速触发并且正在

回答 1 投票 0

PYSimpleGui 事件与 Keyboard.is_pressed('key') 结合使用,每次都有效,程序启动后第一次除外

PYSimpleGui 事件与 Keyboard.is_pressed('key') 结合使用,每次都有效,程序启动后第一次除外。因此,第一次点击永远不会起作用,但其他所有点击都会起作用。 对我的

回答 2 投票 0

当不使用 target.value 时,React 输入会丢失 onChange 中的插入符号位置

我正在尝试从 React 中的输入字段拦截关键事件。我想用不同的键替换每个键,并将插入符位置保留在原来的位置。现在,我尝试了 onChange 和 onKeyDown

回答 1 投票 0

如何在C#控制台应用程序中处理按键事件

我想创建一个控制台应用程序,它将显示在控制台屏幕上按下的键,到目前为止我编写了以下代码: 静态无效主(字符串[]参数) { // 这绝对是错误的,b...

回答 3 投票 0

如何处理控制台应用程序中的按键事件

我想创建一个控制台应用程序,它将显示在控制台屏幕上按下的键,到目前为止我编写了以下代码: 静态无效主(字符串[]参数) { // 这是绝对的...

回答 3 投票 0

C# 退格模拟器删除整个单词而不是仅删除一个字母

我正在编写一个简单的 C# 程序,当我按 Ctrl+G 时,我希望我的程序自动删除任何程序中光标左侧的字符(例如:chrome 浏览器、word 文档、

回答 1 投票 0

Backspace 在 C# 控制台中的 StringBuilder 中无法正常工作

我正在尝试创建一个屏幕,用户可以在其中使用 StringBuilder 写下他们的名字。 我遇到的问题是退格键的功能。我可以删除除...之外的所有字母

回答 2 投票 0

如何在C#控制台中检测“Enter”? [重复]

我对 C# 相当陌生,如果您能帮助我,我会很高兴。 我正在尝试检测何时按下 Enter 键。 Console.Write("**按 Enter**" "执行此操作" 或 &q...

回答 1 投票 0

C# 中输入按键

我尝试了这段代码: 私有无效textBox1_KeyPress(对象发送者,KeyPressEventArgs e) { if (Convert.ToInt32(e.KeyChar) == 13) { MessageBox.Show("按下回车键"); } } 还有那个...

回答 14 投票 0

pynput:仅在窗口处于活动状态时监听

当我在pynput.keyboard.Listener上设置suppress=True并最小化程序窗口时,它会阻止系统监听键盘。 是否可以阻止系统监听ke...

回答 1 投票 0

为什么我应该使用 SendInput 而不是鼠标和键盘事件?

在 Microsoft Learn 上查找如何使用 keybd_event 时,它说: 注意 该函数已被取代。请改用 SendInput。 但是当查看如何使用 SendInput 时,它看起来更简单......

回答 1 投票 0

如何在本机反应中强制 TextInput 增长而 multiline={false} ?

<TextInput ref={inputRef} value={text} style={styles.textInput} returnKeyType="next" placeholder={"placeholder"} scrollEnabled={false} blurOnSubmit={false} onFocus={onFocusInput} textAlignVertical="center" onContentSizeChange={onChangeContentSizeChange} onChangeText={onInputChangeValue} onBlur={onInputBlur} onKeyPress={onInputKeyPress} onSubmitEditing={() => NextScript(id)} multiline={false} numberOfLines={5} /> 逻辑是我想要 onSubmitEditing 带我到下一个 TextInput 字段,并且我需要文本来包装输入的多个文本。如果我启用 multiline,一旦按下回车键,它会在进入下一个输入之前进入下一行,这就是我试图避免的。 是否可以用onSubmitEditing完全取代回车键?每当我按下回车键时,它都会尝试在移动到下一个TextInput之前输入换行符,因此它会创建一个糟糕的用户界面,其中文本在重新定位然后进入下一行之前会稍微向上移动。 如果我将 blurOnSubmit 设置为 true,它会停止,但键盘会在提交时关闭。 如果我将 multiline 设置为 false,它会停止但不会换行。 我创建了一个示例,onKeyPress将允许您在按下回车键时聚焦下一个文本字段。 import { Text, SafeAreaView, StyleSheet, TextInput } from 'react-native'; export default function App() { return ( <SafeAreaView style={styles.container}> <TextInput multiline={true} placeholder={'PLACEHOLDER'} onKeyPress={(e) => { if (e.nativeEvent.key == 'Enter') { console.log('ENTER'); //focusNextTextField(); } }} style={{ borderColor: '#000000', borderWidth: 1 }} /> </SafeAreaView> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignContent: 'center', padding: 8, }, }); 我也面临同样的问题。后来我找到了解决办法。 自定义文本输入处理:您需要一个自定义逻辑来处理文本输入及其在按“Enter”键时的行为。您将以编程方式控制文本换行和导航到下一个输入字段,而不是依赖多行的默认行为。 用 onSubmitEditing 替换 Enter 键:要覆盖“Enter”键的默认行为,您可以使用 onKeyPress 事件。检测何时按下“Enter”键并以编程方式触发 onSubmitEditing 函数。 维护文本换行:由于 multiline={false} 禁用自动文本换行,因此您需要实现一种方法来根据输入的内容大小或字符数手动处理文本换行。 以下是如何实现这一点的概念示例: import React, { useState, useRef } from 'react'; import { TextInput, StyleSheet } from 'react-native'; const CustomTextInput = () => { const [text, setText] = useState(''); const nextInputRef = useRef(null); const onInputKeyPress = (e) => { if (e.nativeEvent.key === 'Enter') { // Replace the Enter key functionality // Call the function you would have in onSubmitEditing handleEnterKeyPress(); } }; const handleEnterKeyPress = () => { // Logic to navigate to next TextInput // Focus the next input field if (nextInputRef.current) { nextInputRef.current.focus(); } // Additional logic if needed to handle text wrapping }; return ( <TextInput value={text} style={styles.textInput} onChangeText={setText} onKeyPress={onInputKeyPress} blurOnSubmit={false} // prevent keyboard from closing // other props /> ); }; const styles = StyleSheet.create({ textInput: { // styling for your text input }, }); export default CustomTextInput;

回答 2 投票 0

如何控制列表元素抛出键盘事件

https://stackblitz.com/edit/react-o1ra7c 用户搜索结果后,用户尝试使用键盘事件箭头需要向下移动。 https://stackblitz.com/edit/react-o1ra7c 用户搜索结果后,用户尝试使用键盘事件箭头需要向下移动。 <div> <input onChange={handleSearchChange}/> <div css={countryDataCss}> {countryList?.map((country) => ( <div key={country.countryCode}> <span css={countryCss}>{country.countryName}</span> <span css={countryDialCodeCss}> {country.countryDialNo} </span> </div> ))} </div> </div> 您可以使用 javascirpt 事件 onkeydown,对于 React 来说是 onKeyDown,它提供了所需的行为,请检查下面的 stackblitz! import React from 'react'; import './style.css'; import { useState } from 'react'; export default function App() { const [searchText, setSearchText] = useState(''); const [selectedCountry, setSelectedCountry] = useState('SG'); const [activeIndex, setActiveIndex] = useState(0); const [selectedDialCode, setSelectedDialCode] = useState('+65'); const countryCodeListResponse = [ { countryCode: 'IND', countryDialNo: '+91', countryName: 'India' }, { countryCode: 'SG', countryDialNo: '+65', countryName: 'Singpare' }, ]; const [countryList, setCountryList] = useState(countryCodeListResponse); function handleSearchChange(e) { const searchText = e.target.value.toLowerCase(); if (countryCodeListResponse) { const updatedList = countryCodeListResponse .filter((el) => el.countryName.toLowerCase().includes(searchText)) .sort( (a, b) => a.countryName.toLowerCase().indexOf(searchText) - b.countryName.toLowerCase().indexOf(searchText) ); setSearchText(searchText); setCountryList(updatedList); } } const onSelectCountry = (code, dialCode) => { setSelectedCountry(code); setSelectedDialCode(dialCode); setSearchText(''); setCountryList(countryCodeListResponse); }; const onKeyDown = (event) => { console.log(event); switch (event.keyCode) { case 38: // arrow up if (activeIndex > 0 && activeIndex <= countryList.length - 1) { setActiveIndex((prev) => prev - 1); } break; case 40: // arrow down if (activeIndex >= 0 && activeIndex < countryList.length - 1) { setActiveIndex((prev) => prev + 1); } break; case 13: const country = countryList[activeIndex]; onSelectCountry(country.countryCode, country.countryDialNo); break; default: break; } }; return ( <div class="dropdown"> <div class="search"> <div> <span>{selectedCountry}</span> <span>{selectedDialCode}</span> </div> <input class="search-input" onKeyDown={(e) => onKeyDown(e)} placeholder="Search" value={searchText} onChange={handleSearchChange} /> </div> <div class="list"> {countryList?.map((country, index) => ( <div onKeyDown={(e) => onKeyDown(e)} className={index === activeIndex ? 'active' : ''} tabIndex="0" key={country.countryCode} onClick={() => onSelectCountry(country.countryCode, country.countryDialNo) } > <span>{country.countryName}</span> <span>{country.countryDialNo}</span> </div> ))} </div> </div> ); } 堆栈闪电战

回答 1 投票 0

如何从另一个 Sub 使用 KeyEventArgs 调用 Sub

我有两个替补 Private Sub kbHook_KeyDown(ByVal Key As System.Windows.Forms.Keys) 处理 KeyHook.KeyDown 和 Private Sub Form1_KeyPressCaps(ByVal key As Object, e As KeyEventArgs) 处理我。

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.