我正在寻找可以与Cocoa NSEvent类一起使用的可用密钥代码的完整列表.的NSEvent类有一个keyCode属性,该属性被定义为unsigned short.以下代码放置在适当的UI对象中时,将在按下键代码时回显它们:
- (void)keyDown:(NSEvent *)theEvent
{
NSLog(@"%d", [theEvent keyCode]);
}
Run Code Online (Sandbox Code Playgroud)
从这段代码中,我可以很容易地看到哪些代码与某些键匹配,但我想找到一个列出所有代码的官方文档.我希望Apple有一个头文件,看起来像这样:
enum {
...
NSKeyCodeLeftArrow = 123,
NSKeyCodeRightArrow = 124,
...
};
Run Code Online (Sandbox Code Playgroud)
但如果有的话,我还没有找到它.
这是我的代码:
function pauseSound() {
var pauseSound = document.getElementById("backgroundMusic");
pauseSound.pause();
}
Run Code Online (Sandbox Code Playgroud)
我想为这段代码添加一个键盘快捷键,我怎么能这样做才能在单击按钮时执行该功能呢?
试图添加一个else if语句,但它不起作用,任何想法?
function doc_keyUp(e) {
if (e.ctrlKey && e.keyCode == 88) {
pauseSound();
}
else if (e.ctrlKey && e.keyCode == 84) {
playSound();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试以下但没有运气.当用户点击UiTextfield我需要自动将键盘视图更改为数字视图时,这可能吗?提前致谢.
相关:JavaScript KeyCode与CharCode
这里有一些你可以在家里或在jsfiddle中尝试的代码:
el.addEventListener( 'keyup', function( e ) {
console.log( 'Keyup event' );
console.log( e.keyCode );
} );
el.addEventListener( 'keypress', function( e ) {
console.log( 'Keypress event' );
console.log( e.keyCode );
} );
Run Code Online (Sandbox Code Playgroud)
为什么keyCode不同?
我可以理解为什么人们只应该使用按键,但我不明白的是,在键盘上给出相同的按键时,两个按键事件如何给出不同的keyCodes.
PS:我并不担心遗留的浏览器支持,我在Chrome中尝试了这个并且感到惊讶,并且找不到解释.
我尝试在swift上创建我的搜索栏,但是当我按下搜索栏时,我有一个问题就是在屏幕上关闭键盘.当我尝试使用textfield时,它可以很好地使用此代码.
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
self.view.endEditing(true)
}
Run Code Online (Sandbox Code Playgroud)
当我按下我的文本字段然后键盘消失时,它工作.我想用我的搜索栏制作这样的东西,因为当我使用搜索栏并使用与textfield相同的方式时,它根本不起作用.任何参考或代码对我都非常有用.
我有一个UISearchBar,它充当表视图的实时过滤器.当键盘通过endEditing:解除时,查询文本和灰色圆形"清除"按钮保持不变.从这里,如果我点击灰色的"清除"按钮,键盘会在文本被清除时重新出现.
我该如何防止这种情况?如果键盘当前未打开,我希望该按钮在不重新打开键盘的情况下清除文本.
当我点击清除按钮时,会调用一个协议方法.但是向UISearchBar发送resignFirstResponder消息对键盘没有任何影响.
如何在Java中使用控制台中的用户获得简单的键盘输入(整数)?我用这些java.io.*东西完成了这个,但它说它已被弃用了.
我现在应该怎么做?
当我的活动ScrollView布局和EditTexts开始时,EditTexts得到焦点并且Android OnScreen键盘打开.
我怎么能避免这种情况?
当我使用LinearLayout和RelativeLayout没有ScrollView它时,它不会发生.
我已经尝试过这种方式了,但它确实有效,但这不是一个好方法:
TextView TextFocus = (TextView) findViewById(R.id.MovileLabel);
TextFocus.setFocusableInTouchMode(true);
TextFocus.requestFocus();
Run Code Online (Sandbox Code Playgroud)
接下来你有一些我的布局有这个问题的例子,当这个Activity开始时,焦点转到第一个EditText,描述和Android键盘自动打开,这非常烦人.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px">
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/UserLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13px"
android:text="@string/userlabel"/>
<TextView
android:id="@+id/User"
android:layout_alignBaseline="@id/UserLabel"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"/>
</RelativeLayout>
<View
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#808080"
android:layout_marginTop="5px"
android:layout_marginBottom="12px"/>
<RelativeLayout
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/DescriptionLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/desclabel"
android:layout_marginTop="13px"/>
<EditText
android:id="@+id/Description"
android:layout_alignBaseline="@id/DescriptionLabel" …Run Code Online (Sandbox Code Playgroud) textEditText和TextView 的inputType的大多数实现(除了URI,密码等)都允许表情符号 - 尽管在大多数Google键盘配置中,此按钮是隐藏的.有没有办法禁止在EditText中输入表情符号?是否有一个inputType参数可以与textMultiLine禁用表情符号配对?
请解释一下软键盘的问题.例如,我在我的活动或对话片段或片段活动上有一个EditText,无论如何.这里是:
<EditText
android:id="@+id/edPswrd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
Run Code Online (Sandbox Code Playgroud)
当它第一次显示我没有看到软键盘并且必须按editText才能获得焦点并且键盘出现.另一个活动是不同的,当它出现在屏幕上时,键盘在没有任何帮助的情况下加载.我以为
<requestFocus />
意味着EditText将被聚焦并且键盘将出现,但我错了.
如何管理哪些组件将获得焦点,键盘将自动显示.
keyboard ×10
android ×3
focus ×2
iphone ×2
java ×2
javascript ×2
uisearchbar ×2
appearance ×1
cocoa ×1
console ×1
emoji ×1
events ×1
input ×1
ios ×1
objective-c ×1
scripting ×1
scrollview ×1
searchbar ×1
shortcut ×1
swift ×1
uitextfield ×1