天道酬勤,学无止境

backspace

Bash 读取退格按钮行为问题(Bash read backspace button behavior problem)

问题 在 bash 中使用 read 时,按退格键不会删除输入的最后一个字符,而是会在输入缓冲区中附加一个退格符。 有什么方法可以更改它,以便删除删除从输入中键入的最后一个键? 如果是这样怎么办? 这是一个简短的示例程序,如果有帮助,我正在使用它: #!/bin/bash colour(){ #$1=text to colourise $2=colour id printf "%s%s%s" $(tput setaf $2) "$1" $(tput sgr0) } game_over() { #$1=message $2=score printf "\n%s\n%s\n" "$(colour "Game Over!" 1)" "$1" printf "Your score: %s\n" "$(colour $2 3)" exit 0 } score=0 clear while true; do word=$(shuf -n1 /usr/share/dict/words) #random word from dictionary word=${word,,} #to lower case len=${#word} let "timeout=(3+$len)/2" printf "%s (time %s): " "$(colour $word 2)" "$(colour

2021-12-01 09:08:43    分类:技术分享    bash   backspace

如何在 keyTypedEvent 中检测退格(How to detect backspace in a keyTypedEvent)

问题 我正在使用 Netbeans 的 bean 形式来创建我的 GUI。 我已将 keyTyped 事件添加到 JTextArea 中,并且我想检测键入的键是否为Backspace 。 由于其他原因,我正在使用 keyTyped 事件,所以我不能只使用 keyPressed 事件。 这是生成的代码(以及我的 if 检查): private void langArea1KeyTyped(java.awt.event.KeyEvent evt) { if(evt.getChar()== backspace) //how can I make this check? } evt.getKeyCode()总是返回 0 独立于键入的键。 evt.getKeyChar()只是删除打印时打印的最后一个字符,所以我不能使用System.out.print(evt.getKeyChar())来检测它的值并检查它。 如何检测键入的键是否为Backspace (或Delete )? 回答1 backspace和delete具有以下常量: VK_BACK_SPACE VK_DELETE 此处列出了常量:Class KeyEvent 来自 docs.oracle.com 警告:除了那些由 Java 语言定义的键( VK_ENTER 、 VK_BACK_SPACE和VK_TAB ),不要依赖VK_常量的值。

2021-11-29 19:02:12    分类:技术分享    java   netbeans   keyboard-events   backspace

Java KeyListener:KeyTyped Backspace,Esc 作为输入(Java KeyListener: KeyTyped Backspace, Esc as input)

问题 在KeyTyped方法中,如何判断是否按下了Backspace或Esc ? 回答1 假设您已正确附加 KeyListener 并已实现该 KeyListener 所需的方法,要检测特定的按键,只需添加以下代码: public void keyReleased(KeyEvent ke) { if(ke.getKeyCode() == KeyEvent.VK_BACK_SPACE) { //code to execute if backspace is pressed } if(ke.getKeyCode() == KeyEvent.VK_ESCAPE) { //code to execute if escape is pressed } } KeyEvent 类 javadocs 可以在以下链接中找到:KeyEvent javadocs。 在那里您可以找到在实现 Java KeyListeners 和 KeyEvents 时用于检测键盘输入的所有 Java 虚拟键码的列表。 关于 KeyListeners 的更多信息可以在这里找到:How to Write a Key Listener。 要使用keyTyped方法,请参阅gangqinlaohu's answer。 回答2 http://www.fileformat.info/info/unicode/char/8/index

2021-11-26 14:01:36    分类:技术分享    java   keylistener   backspace

Bash read backspace button behavior problem

When using read in bash, pressing backspace does not delete the last character entered, but appears to append a backspace to the input buffer. Is there any way I can change it so that delete removes the last key typed from the input? If so how? Here's a short example prog I'm using it with if it's of any help: #!/bin/bash colour(){ #$1=text to colourise $2=colour id printf "%s%s%s" $(tput setaf $2) "$1" $(tput sgr0) } game_over() { #$1=message $2=score printf "\n%s\n%s\n" "$(colour "Game Over!" 1)" "$1" printf "Your score: %s\n" "$(colour $2 3)" exit 0 } score=0 clear while true; do word=$

2021-11-22 20:43:34    分类:问答    bash   backspace

Java KeyListener: KeyTyped Backspace, Esc as input

Inside the KeyTyped method, how do I tell if Backspace or Esc is being pressed?

2021-11-21 13:24:36    分类:问答    java   keylistener   backspace

How to detect backspace in a keyTypedEvent

I'm using Netbeans' bean form to create my GUI.I've added a keyTyped event to a JTextArea and I want to detect if the typed key is a Backspace. I'm using keyTyped event for other reasons so I cannot just use the keyPressed event. This is the generated code (and my if check): private void langArea1KeyTyped(java.awt.event.KeyEvent evt) { if(evt.getChar()== backspace) //how can I make this check? } evt.getKeyCode() always returns 0 independent of the typed key. evt.getKeyChar() simply deletes the last character printed when printed so I can't use System.out.print(evt.getKeyChar()) to detect its

2021-11-20 13:39:57    分类:问答    java   netbeans   keyboard-events   backspace

使用 jQuery oninput 事件在输入表单的文本中启用 Backspace?(Enable Backspace with jQuery oninput event within the text on an input form?)

问题 我有一个输入表单,它应用了一个 jQuery 事件,在用户输入周围创建方括号。 问题是该事件阻止了使用退格键删除文本的能力。 我正在寻找一种方法来检查是否按下了退格键并防止代码运行。 jQuery 脚本 function test(obj) { var oldVal = obj.val().replace(/\[/g,\'\'); oldVal = oldVal.replace(/\]/g,\'\'); var val = \'[\' + oldVal + \']\'; obj.val(val); 输入表格 oninput="test($(this));" 回答1 function test(obj,e) { if(!(e.which == 8)){ var oldVal = obj.val().replace(/\[/g,''); oldVal = oldVal.replace(/\]/g,''); var val = '[' + oldVal + ']'; obj.val(val); } } 并将事件作为参数传递.. <input class="text-box" onkeyup="test($(this),event)">

2021-11-19 18:00:40    分类:技术分享    javascript   jquery   text   input   backspace

Enable Backspace with jQuery oninput event within the text on an input form?

I have an input form that has a jQuery event applied to it that creates square brackets around the users input. The issue is that the event prevents the ability to use backspace to delete the text. I'm looking for a way to check if backspace is being pressed and prevent the code from runnning. jQuery Script function test(obj) { var oldVal = obj.val().replace(/\[/g,\'\'); oldVal = oldVal.replace(/\]/g,\'\'); var val = \'[\' + oldVal + \']\'; obj.val(val); Input Form oninput="test($(this));"

2021-11-13 09:06:13    分类:问答    javascript   jquery   text   input   backspace

Android:按下数字键寄存器退格键(Android: Numeric key register backspace pressed)

问题 我有一个 EditText 只接受这样定义的数字: <EditText android:id="@+id/routeInit_price" android:layout_height="wrap_content" android:layout_width="120dp" android:layout_gravity="center_horizontal" android:lines="1" android:inputType="numberDecimal"/> 我正在验证是否有像下面这样的有效输入来启用/禁用按钮。 但是,我没有收到有关退格/删除按钮按下事件的事件。 我该如何解决? 因为当 EditText 为空时,按钮应该被禁用。 EditText priceField = (EditText)findViewById(R.id.routeInit_price); priceField.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if(keyEvent.getAction() == KeyEvent.ACTION_UP) { if(((EditText)view).getText(

2021-11-11 15:49:37    分类:技术分享    android   events   android-edittext   backspace

Android: Numeric key register backspace pressed

I have an EditText which only accepts numeric numbers defined like this: <EditText android:id="@+id/routeInit_price" android:layout_height="wrap_content" android:layout_width="120dp" android:layout_gravity="center_horizontal" android:lines="1" android:inputType="numberDecimal"/> I am validating if there is a valid input like below to enable/disable a button. However, I doesn't receive an event on the backspace/delete button pressed event. How can I fix that? Because when the EditText is empty the button should be diabled. EditText priceField = (EditText)findViewById(R.id.routeInit_price)

2021-11-10 19:25:08    分类:问答    android   events   android-edittext   backspace