问题描述
我有 UIWebView
,因为我允许在运行时进行编辑。
I have on UIWebView
in that i am allowing editing at runtime.
现在当我点击 UIWebView
然后iPad键盘打开写入,
现在我的要求是如何检测我点击了iPad键盘的输入键?。
Now when i click on UIWebView
then iPad keyboard opens for writing,now my requirement is how to detect that I have clicked on enter key of iPad keyboard?.
我知道如果我们在 UITextView
或 UITextField
中进行编辑,我们可以实现这一点使用它的委托。帮助我!
I know that we can achieve this if we are editing in UITextView
or UITextField
with using it's delegates.Help me!
我在javascript中有一个检测它的函数。
I have one function in javascript that detects it.
function returnEnterPress(e){
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
// ENTER KEY MUNBER IS 13 // KD
if(key == 13)
{
//alert('enter');
}
return false;
}
现在可以使用objective-c代码调用它并获得返回值喜欢真假吗?
Now can i get call it using objective-c code and can get return value like true or false?
推荐答案
我通过这样的javascript完成了我的工作......
I done my work by javascript like this...
在HTML文件中
function returnEnterPress(e){
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
// ENTER KEY MUNBER IS 13 // KD
if(key == 13)
{
window.location.href = 'enterClicked/0';
}
else
{
var range = window.getSelection().getRangeAt(0).endOffset;
if(range == 0)
{
window.location.href = 'enterClicked/'+range;
}
}
return true;
}
<body onKeyPress="return returnEnterPress(event)">
在我的Objective-c代码中
In my Objective-c Code
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if([[[request URL] absoluteString] rangeOfString:@"enterClicked"].location!=NSNotFound) // When "enterClicked" found
{
//Do your desired work
return NO;
}
}
这篇关于如何检测键盘输入键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!