導航:首頁 > 編程語言 > js虛擬鍵盤代碼

js虛擬鍵盤代碼

發布時間:2023-04-16 11:52:10

『壹』 移動web 怎麼捕獲虛擬鍵盤彈出和關閉事件

1、當虛擬鍵盤彈出的時候,window的resize事件會被觸發,問題里的input是使用position:fixed嗎,如果是position: fixed,在resize觸發時應該會自動調整位置吧。

2、以下js可以實現此效果:

var wHeight = windows.innerHeight; //獲取初始可視窗口高度

$(window).resize(function() { //監測窗口大小的變化事件

var hh = windows.innerHeight; //當前可視窗口高度

var viewTop = $(window).scrollTop(); //可視窗口高度頂部距離網頁頂部的距離

if(wHeight > hh){ //可以作為虛擬鍵盤彈出事件碧攜掘

$("body,html").animate({scrollTop:viewTop+100}); //調隱衡整可視頁面的位置

}else{ //可以作為虛擬鍵盤關閉事悔核件

$("body,html").animate({scrollTop:viewTop-100});

}

wHeight = hh;

});

『貳』 求js虛擬鍵盤鍵盤

按照apollo47的說法
當你取回來後再轉換一次就好
return orgStr.replaceAll("<br>","\r\n" );

我們再做開發時候一般會做個轉換的工具
或者使用FCKEditor這種開源的組件
一般採用後者來做 網上很多 下個拿來就用

『叄』 用js怎麼寫一個回車鍵盤事件

<script type="text/javascript" language=JavaScript charset="UTF-8">

document.onkeydown=function(event){

var e = event || window.event || arguments.callee.caller.arguments[0];

if(e && e.keyCode==27){ // 按 Esc

//要做的事情

}

if(e && e.keyCode==113){ // 按 F2

//要做的事情

}

if(e && e.keyCode==13){ // enter 鍵

//要做的事情

}

};

</script>

(3)js虛擬鍵盤代碼擴展閱讀:

Js鍵盤事件

keydown:按鍵按下

keyup:按鍵抬起

keypress:按鍵按下抬起

<body>

<input id="name" type="text" onkeydown="myKeyDown(this.id)" onkeyup="myKeyUp(this.id)">

</body>

<script>

/*輸出輸入的字元*/

function myKeyDown(id) {

console.log(document.getElementById(id).value);

}

/*按鍵結束,字體轉換為大寫*/

function myKeyUp(id) {

var text = document.getElementById(id).value;

document.getElementById(id).value = text.toUpperCase();

}

</script>

常用的鍵盤事件對應的鍵碼:

keyCode 8 = BackSpace BackSpace

keyCode 9 = Tab Tab

keyCode 12 = Clear

keyCode 13 = Enter

keyCode 16 = Shift_L

keyCode 17 = Control_L

keyCode 18 = Alt_L

keyCode 19 = Pause

keyCode 20 = Caps_Lock

keyCode 27 = Escape Escape

『肆』 js自動彈出手機鍵盤,而不是要點擊文本框再彈出虛擬鍵盤的,如何實現

autofocus 屬性 : 文褲磨弊本輸入欄位被設置為當頁面加胡族游殲載時獲得焦點

<input type="text" autofocus="autofocus"> 試試這個

『伍』 想請教一下各位高手虛擬鍵盤應該如何寫。

使用keybd_event函數:
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
你是做了很多按鈕,然後響應按鈕按下的消息嗎?如果是這樣的話,就在按鈕按下的消息函數里添加如下的代碼就行了(反正就是添加到你姿襲需要模擬按鍵的那個地方):
keybd_event(VK_H, 0, 0, 0); // 模卜冊消擬按下H鍵
要模擬其他鍵只需要把第一個參數改成相應的虛鍵值就行了,所有的虛鍵值表示如下:
KEY_EVENT_BASE
The base identifier for all UIKeyEvent events.
KEY_PRESSED
The key pressed event type.
KEY_RELEASED
The key released event type.
KEY_TYPED
The key typed event type, which is generated by a combination of a key press followed by a key release.
VK_0
VK_0 through VK_9 are the same as ASCII "0" through "9" (0x30 - 0x39).
VK_1
A virtual key code for the ASCII "1" key.
VK_2
A virtual key code for the ASCII "型知2" key.
VK_3
A virtual key code for the ASCII "3" key.
VK_4
A virtual key code for the ASCII "4" key.
VK_5
A virtual key code for the ASCII "5" key.
VK_6
A virtual key code for the ASCII "6" key.
VK_7
A virtual key code for the ASCII "7" key.
VK_8
A virtual key code for the ASCII "8" key.
VK_9
A virtual key code for the ASCII "9" key.
VK_A
VK_A through VK_Z are the same as ASCII "A" through "Z" (0x41 - 0x5A).
VK_ACCEPT
For Asian keyboards.
VK_ADD
A virtual key code for the numeric keypad PLUS SIGN (+) key.
VK_ALT
A virtual key code for the ALT key.
VK_B
A virtual key code for the ASCII "B" key.
VK_BACK_QUOTE
A virtual key code for the apostrophe (`) key.
VK_BACK_SLASH
A virtual key code for the BACKSLASH (\) key.
VK_BACK_SPACE
A virtual key code for the BACKSPACE key.
VK_C
A virtual key code for the ASCII "C" key.
VK_CANCEL
A virtual key code for the CANCEL key.
VK_CAPS_LOCK
A virtual key code for the CAPS LOCK key.
VK_CLEAR
A virtual key code for the CLEAR key.
VK_CLOSE_BRACKET
A virtual key code for the CLOSE BRACKET (]) key.
VK_COMMA
A virtual key code for the COMMA (,) key.
VK_CONTROL
A virtual key code for the CTRL key.
VK_CONVERT
For Asian keyboards.
VK_D
A virtual key code for the ASCII "D" key.
VK_DECIMAL
A virtual key code for the numeric keypad DECIMAL POINT (.) key.
VK_DELETE
A virtual key code for the DELETE key.
VK_DIVIDE
A virtual key code for the numeric keypad DIVISION (/) key.
VK_DOWN
A virtual key code for the DOWN ARROW key.
VK_E
A virtual key code for the ASCII "E" key.
VK_END
A virtual key code for the END key.
VK_ENTER
A virtual key code for the ENTER key.
VK_EQUALS
A virtual key code for the EQUAL SIGN (=) key.
VK_ESCAPE
A virtual key code for the ESC key.
VK_F
A virtual key code for the ASCII "F" key.
VK_F1
A virtual key code for the F1 key.
VK_F10
A virtual key code for the F10 key.
VK_F11
A virtual key code for the F11 key.
VK_F12
A virtual key code for the F12 key.
VK_F2
A virtual key code for the F2 key.
VK_F3
A virtual key code for the F3 key.
VK_F4
A virtual key code for the F4 key.
VK_F5
A virtual key code for the F5 key.
VK_F6
A virtual key code for the F6 key.
VK_F7
A virtual key code for the F7 key.
VK_F8
A virtual key code for the F8 key.
VK_F9
A virtual key code for the F9 key.
VK_FINAL
For Asian keyboards.
VK_G
A virtual key code for the ASCII "G" key.
VK_H
A virtual key code for the ASCII "H" key.
VK_HELP
A virtual key code for the HELP key.
VK_HOME
A virtual key code for the HOME key.
VK_I
A virtual key code for the ASCII "I" key.
VK_INSERT
A virtual key code for the INSERT key.
VK_J
A virtual key code for the ASCII "J" key.
VK_K
A virtual key code for the ASCII "K" key.
VK_KANA
For Asian keyboards.
VK_KANJI
For Asian keyboards.
VK_L
A virtual key code for the ASCII "L" key.
VK_LEFT
A virtual key code for the LEFT ARROW key.
VK_M
A virtual key code for the ASCII "M" key.
VK_META
A virtual key code for the Application key (found on Microsoft® Windows® 95 keyboards).
VK_MODECHANGE
For Asian keyboards.
VK_MULTIPLY
A virtual key code for the numeric keypad MULTIPLICATION (*) key.
VK_N
A virtual key code for the ASCII "N" key.
VK_NONCONVERT
For Asian keyboards.
VK_NUM_LOCK
A virtual key code for the NUM LOCK key.
VK_NUMPAD0
A virtual key code for the numeric keypad "0" key.
VK_NUMPAD1
A virtual key code for the numeric keypad "1" key.
VK_NUMPAD2
A virtual key code for the numeric keypad "2" key.
VK_NUMPAD3
A virtual key code for the numeric keypad "3" key.
VK_NUMPAD4
A virtual key code for the numeric keypad "4" key.
VK_NUMPAD5
A virtual key code for the numeric keypad "5" key.
VK_NUMPAD6
A virtual key code for the numeric keypad "6" key.
VK_NUMPAD7
A virtual key code for the numeric keypad "7" key.
VK_NUMPAD8
A virtual key code for the numeric keypad "8" key.
VK_NUMPAD9
A virtual key code for the numeric keypad "9" key.
VK_O
A virtual key code for the ASCII "O" key.
VK_OPEN_BRACKET
A virtual key code for the OPEN BRACKET ([) key.
VK_P
A virtual key code for the ASCII "P" key.
VK_PAGE_DOWN
A virtual key code for the PAGE DOWN key.
VK_PAGE_UP
A virtual key code for the PAGE UP key.
VK_PAUSE
A virtual key code for the PAUSE (BREAK) key.
VK_PERIOD
A virtual key code for the PERIOD (.) key.
VK_PRINTSCREEN
A virtual key code for the PRINT SCREEN key.
VK_Q
A virtual key code for the ASCII "Q" key.
VK_QUOTE
A virtual key code for the QUOTATION MARK key.
VK_R
A virtual key code for the ASCII "R" key.
VK_RIGHT
A virtual key code for the RIGHT ARROW key.
VK_S
A virtual key code for the ASCII "S" key.
VK_SCROLL_LOCK
A virtual key code for the SCROLL LOCK key.
VK_SEMICOLON
A virtual key code for the SEMICOLON (;) key.
VK_SEPARATER
VK_SHIFT
A virtual key code for the SHIFT key.
VK_SLASH
A virtual key code for the forward slash (/) key.
VK_SPACE
A virtual key code for the SPACEBAR key.
VK_SUBTRACT
A virtual key code for the numeric keypad MINUS SIGN (-) key.
VK_T
A virtual key code for the ASCII "T" key.
VK_TAB
A virtual key code for the TAB key.
VK_U
A virtual key code for the ASCII "U" key.
VK_UNDEFINED
KEY_TYPED events do not have a defined key code.
VK_UP
A virtual key code for the UP ARROW key.
VK_V
A virtual key code for the ASCII "V" key.
VK_W
A virtual key code for the ASCII "W" key.
VK_X
A virtual key code for the ASCII "X" key.
VK_Y
A virtual key code for the ASCII "Y" key.
VK_Z
A virtual key code for the ASCII "Z" key.

『陸』 js怎麼聽移動端鍵盤展開事件

方法一實現代碼:

var winHeight = $(window).height();

$(window).resize(function(){

var thisHeight=$(this).height();

if(winHeight - thisHeight >50){

//窗口發生改變(大),故此時鍵盤彈出

//當軟鍵盤彈出,在這裡面操作

}else{

//窗口發生改變(小),故此時鍵盤收起

//當軟鍵盤收起,在此處操作

}

});

方法二:監控鍵盤。

監控的方式其實篩選下來也不過兩種:

① 時鍾setInterval不停監控

系統級別的監控,比如鍵盤出現時候通知window一個事件,但是很遺憾現在還沒有這個事件,但是這個事件等於

input類元素獲取焦點 == 彈出虛擬鍵盤

input類元素失去焦點 == 收起虛擬鍵盤

基於系統監控這點,我們還可以監控resize事件或者scroll事件,但是經過我的測試。

setInterval表現比較好.於是,我們簡單寫一段代碼,可靠是否滿足需求:

window.alert = function (msg) {

$('body').append('<div>' + msg + '</div>')

};

function fixedWatch(el) {

if(document.activeElement.nodeName == 'INPUT'){

el.css('position', 'static');

} else {

el.css('position', 'fixed');

}

}

setInterval(function () {

fixedWatch($('#headerview header'));

}, 500);

『柒』 如何用js輸出鍵盤按鍵

<input type="button" name="btn" value="點擊101"
onclick=" cal(prompt('請輸入第一個鍵盤按鍵字母:'),prompt('請輸入第二個鍵盤按鍵字母:')) " />
<script type="text/javascript">
function cal(num01,num02){
/*var num11 = parseInt(num01);
var num22 = parseInt(num02);*/
alert(num01);
alert(num02);
}
</script>

『捌』 js怎麼控制虛擬鍵盤彈出和收起

js 移動端關於頁面布局,如果底部有position:fixed的盒子,又有input,當軟鍵盤彈出收起都會影響頁面布局。這時候可以監聽resize事件,代碼如下,而ios沒有相關事件。
var winHeight = $(window).height(); //獲取當前頁面高度$(window).resize(function(){ var thisHeight=$(this).height(); if(winHeight - thisHeight >50){ //當軟鍵盤彈出,在這裡面操作 }else{ //當軟鍵盤收起,在此處操作 }
});

/**
* 解決ios鍵盤彈出遮擋input
*/
function iosInput() {
if(isIos()){
$('.chart-footer').css('position','absolute');
//解決第三方軟鍵盤喚起時底部input輸入框被遮擋問題
var bfscrolltop = document.body.scrollTop;//獲取軟鍵盤喚起前瀏覽器滾動部分的高度
$(".chart-input").focus(function(){//在這里『input.inputframe』是我的底部輸入欄的輸入框,當它獲取焦點時觸發事件
interval = setInterval(function(){//設置一個計時器,時間設置與軟鍵盤彈出所需時間相近
document.body.scrollTop = document.body.scrollHeight;//獲取焦點後將瀏覽器內所有內容高度賦給瀏覽器滾動部分高度
},100)
}).blur(function(){//設定輸入框失去焦點時的事件
clearInterval(interval);//清除計時器
document.body.scrollTop = bfscrolltop;
//將軟鍵盤喚起前的瀏覽器滾動部分高度重新賦給改變後的高度
});
}
}
iosInput();

『玖』 虛擬鍵盤按鍵的代碼是什麼

set WshShell = WScript.CreateObject("WScript.Shell") WshShell.SendKeys ("哪祥枝李敏宴團^a") 其中^ 是Ctrl鍵s

『拾』 js手機端如何點擊某個按鈕自動彈出虛擬鍵盤,急~~~~~~~!!!

JS做事可以的啊,HTML5其實就是大量的JS介面,不過好像挺麻煩啊

閱讀全文

與js虛擬鍵盤代碼相關的資料

熱點內容
圖形處理哪個編程語言好用 瀏覽:40
fc熱血籃球手機安卓 瀏覽:136
達內和編程貓哪個好 瀏覽:30
motoxt800刷機教程 瀏覽:591
有了中標文件單價該如何審計結算 瀏覽:57
港版蘋果616G多少錢最新報價 瀏覽:6
揭陽學編程哪個好 瀏覽:315
蘋果護眼壁紙 瀏覽:699
pcsx2按鍵配置文件 瀏覽:740
快賺鎖屏密碼忘了怎麼辦 瀏覽:849
後綴是acd是什麼文件 瀏覽:593
電腦無法打開視頻文件怎麼辦 瀏覽:904
如何簡化applewatch上的app 瀏覽:646
王者榮耀紫色字體代碼 瀏覽:186
surfacepro4系統版本 瀏覽:655
一加手機升級文件在哪個文件夾 瀏覽:537
u盤裝不了4g文件 瀏覽:740
豆神美育app怎麼退款 瀏覽:530
微信吃葯表情動態 瀏覽:425
網路廣播怎麼保存錄音 瀏覽:777

友情鏈接