當前位置:首頁 » 操作系統 » softkeyboard源碼

softkeyboard源碼

發布時間: 2022-08-04 13:01:56

❶ 高分求一個用C#寫的鍵盤或滑鼠的鉤子源代碼

//*************************鍵盤鉤子代碼QQ:475476245**********************
//定義變數
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
static int hKeyboardHook = 0;
HookProc KeyboardHookProcere;
/*************************
* 聲明API函數
* ***********************/
// 安裝鉤子 (using System.Runtime.InteropServices;)
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingC.StdCall)]
public static extern int SetWindowsHookEx(int idHook,HookProc lpfn, IntPtr hInstance, int threadId);
// 卸載鉤子
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingC.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
// 繼續下一個鉤子
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingC.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
// 取得當前線程編號(線程鉤子需要用到)
[DllImport("kernel32.dll")]
static extern int GetCurrentThreadId();
//鉤子子程:就是鉤子所要做的事情
private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
if (nCode >= 0)
{
/****************
//線程鍵盤鉤子判斷是否按下鍵
Keys keyData = (Keys)wParam;
if(lParam.ToInt32() > 0)
{
// 鍵盤按下
}
if(lParam.ToInt32() < 0)
{
// 鍵盤抬起
}
****************/
/****************
//全局鍵盤鉤子判斷是否按下鍵
wParam = = 0x100 // 鍵盤按下
wParam = = 0x101 // 鍵盤抬起
****************/
KeyMSG m = (KeyMSG) Marshal.PtrToStructure(lParam, typeof(KeyMSG));//鍵盤
// 在這里添加你想要做是事情(比如把鍵盤nCode記錄下來,搞個郵件發送程序發到自己的郵箱去)
return 0;//如果返回1,則結束消息,這個消息到此為止,不再傳遞。如果返回0或調用CallNextHookEx函數則消息出了這個鉤子繼續往下傳遞,也就是傳給消息真正的接受者
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
//鍵盤結構
public struct KeyMSG
{
public int vkCode; //鍵值
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
// 安裝鉤子
public void HookStart()
{
if(hKeyboardHook == 0)
{
// 創建HookProc實例
KeyboardHookProcere = new HookProc(KeyboardHookProc);
// 設置線程鉤子

hKeyboardHook = SetWindowsHookEx( 13,KeyboardHookProcere,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetMoles()[0]),0);

//************************************
//鍵盤線程鉤子
//SetWindowsHookEx( 2,KeyboardHookProcere, IntPtr.Zero, GetCurrentThreadId()); //GetCurrentThreadId()為要監視的線程ID,你完全可以自己寫個方法獲取QQ的線程哦
//鍵盤全局鉤子,需要引用空間(using System.Reflection;)
//SetWindowsHookEx( 13,KeyboardHookProcere,Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetMoles()[0]),0);
//
//關於SetWindowsHookEx (int idHook, HookProc lpfn, IntPtr hInstance, int threadId)函數將鉤子加入到鉤子鏈表中,說明一下四個參數:
//idHook 鉤子類型,即確定鉤子監聽何種消息,上面的代碼中設為2,即監聽鍵盤消息並且是線程鉤子,如果是全局鉤子監聽鍵盤消息應設為13,
//線程鉤子監聽滑鼠消息設為7,全局鉤子監聽滑鼠消息設為14。
//
//lpfn 鉤子子程的地址指針。如果dwThreadId參數為0 或是一個由別的進程創建的線程的標識,lpfn必須指向DLL中的鉤子子程。 除此以外,lpfn可
//以指向當前進程的一段鉤子子程代碼。鉤子函數的入口地址,當鉤子鉤到任何消息後便調用這個函數。
//
//hInstance應用程序實例的句柄。標識包含lpfn所指的子程的DLL。如果threadId 標識當前進程創建的一個線程,而且子程代碼位於當前
//進程,hInstance必須為NULL。可以很簡單的設定其為本應用程序的實例句柄。
//
//threadedId 與安裝的鉤子子程相關聯的線程的標識符。如果為0,鉤子子程與所有的線程關聯,即為全局鉤子。
//************************************

// 如果設置鉤子失敗
if(hKeyboardHook == 0 )
{
HookStop();
throw new Exception("SetWindowsHookEx failed.");
}
}
}
// 卸載鉤子
public void HookStop()
{
bool retKeyboard = true;
if(hKeyboardHook != 0)
{
retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = 0;
}
if (!( retKeyboard))
throw new Exception("UnhookWindowsHookEx failed.");
}
//*****************************

❷ Android開發怎麼調試Service

Android開發如何調試Service

Android 開發中,添加代碼對Service 進行調試 。

介紹
以調試 模式啟動Android 項目時,在service 中設置斷點,調試 器不會停止下來
解決方法
所有的這種情況下,都是在代碼中聲明。調用的方法是:

android.os.Debug.waitForDebugger();

舉個例子,SoftKeyboard:

public class SoftKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener { @Override public void onConfigurationChanged(Configuration newConfig) { Log.d("SoftKeyboard", "onConfigurationChanged()"); /* now let's wait until the debugger attaches */ android.os.Debug.waitForDebugger(); super.onConfigurationChanged(newConfig); /* do something useful... */ }

代碼中你可以看到,首先是調用了日誌記錄器logger,代碼運行到這里時,會將在logcat中添加一條記錄,這是跟蹤代碼運行的一種方法,如果不需要在斷點上停止時可以使用。但通常為了更詳細的調試 ,這是不足夠的。
第二條語句等待添加調試 器,添加了這條語句之後,可以在這個方法的任何地方添加斷點。
Activity也是應用的部分時調試 Service 就更加容易了。那種情況下,首先需要啟動Activity,調試 器也可以在Service 的斷點中停止下來,不需要調用 waitForDebugger()。

❸ 急需!求一個網頁中的虛擬鍵盤源碼

javascript模擬虛擬鍵盤 網上找的 希望對你有用 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>softkeyboard:code by meixx</title> <script language="javascript"> var oPopUp=null; function SoftKeyboard(pwdObj){ oPopUp=window.createPopup(); var popBody=oPopUp.document.body; popBody.style.backgroundColor = "#FFFF99"; popBody.style.border = "solid black 1px"; WriteToPopup(oPopUp,pwdObj); oPopUp.show(0,22,325,136,pwdObj); } function WriteToPopup(oPopUp,pwdObj){ var strHTML="<html><head>"; strHTML+='<meta http-equiv="Content-Type" content="text/html; charset=gb2312">'; strHTML+='<style type="text/css">'; strHTML+='.tdnormal{text-align:center; background-image:url(images/bz.GIF); font:13px; color:black; background-repeat:no-repeat; background-position:100% 100%}'; strHTML+='.tdover{text-align:center; background-image:url(images/z.GIF); font:13px; color:black}'; strHTML+='.tdclick{text-align:center; background-image:url(images/zz.GIF); font:13px; color:white}'; strHTML+='.button{border:0;width:90%; height:95%; }'; strHTML+='</style>'; strHTML+='<script language="javascript">'; strHTML+='var arrLow=new Array("`","1","2","3","4","5","6","7","8","9","0","-","=","\\\\","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","[","]",";","\'",",",".","/","");'; strHTML+='var arrUp =new Array("~","!","@","#","$","%","^","&","*","(",")","_","+","|","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","{","}",":","\\"","<",">","?",""); '; strHTML+='var curOverTd=null; var curClkTd=null; var CapsStatus="black";'; strHTML+='var pwdObjectId=parent.document.getElementById("'+pwdObj.id+'");'; strHTML+='function TdMouseOver(TdObj){ '; strHTML+=' TdObj.className ="tdover"; '; strHTML+=' curOverTd=TdObj;} '; strHTML+='function TdMouseOut(TdObj){ '; strHTML+=' if(curClkTd==TdObj)'; strHTML+=' TdObj.className ="tdclick"; '; strHTML+=' else'; strHTML+=' TdObj.className ="tdnormal"; '; strHTML+=' } '; strHTML+='function TdMouseClk(TdObj){ '; strHTML+=' if(curClkTd)'; strHTML+=' curClkTd.className ="tdnormal"; '; strHTML+=' TdObj.className ="tdclick"; '; strHTML+=' curClkTd=TdObj; '; strHTML+=' curOverTd=null; '; strHTML+=' pwdObjectId.value+=TdObj.innerText;'; strHTML+=' }'; strHTML+=' function btnCapsDown(btnObj){'; strHTML+=' if(CapsStatus=="black"){ CapsStatus="green"; ChgText(arrUp);}'; strHTML+=' else{ CapsStatus="black"; ChgText(arrLow);}; '; strHTML+=' btnObj.style.color=CapsStatus=="black"?"#000000":"#33FF66";'; strHTML+=' if(curClkTd){ if(curClkTd.className=="tdclick") curClkTd.className="tdnormal"; else curClkTd.className="tdclick"; }'; strHTML+=' btnObj.style.color=CapsStatus=="black"?"#000000":"#33FF66";'; strHTML+=' }'; strHTML+=' function ChgText(arr){'; strHTML+=' var table=document.getElementById("tbKeyboard");'; strHTML+=' for(var i=0;i<4;i++)'; strHTML+=' for(var j=0;j<12;j++)'; strHTML+=' table.rows[i].cells[j].innerText=arr[12*i+j];'; strHTML+=' }'; strHTML+=' function btnSpaceDown(){'; strHTML+=' pwdObjectId.value+=" "'; strHTML+=' }'; strHTML+=' function btnBackDown(){'; strHTML+=' pwdObjectId.value=pwdObjectId.value.substring(0,pwdObjectId.value.length-1)'; strHTML+=' }'; strHTML+=' function btnEnterDown(){'; strHTML+=' parent.oPopUp.hide();'; strHTML+=' }'; strHTML+='</scr'+'ipt></head> '; strHTML+='<body bgcolor="#FFFFFF" style="margin:2;filter:Alpha(opacity=100); border:1 solid #3C97C6;overflow:hidden;" oncontextmenu="javascript:event.returnValue=false;" onselectstart="javascript:event.returnValue=false;"> '; strHTML+='<table id="tbKeyboard" cellpadding="0" cellspacing="0" border="1" style="TABLE-LAYOUT: fixed; width:100%;height:100%; border-collapse:collapse; cursor:default" bordercolor="#FFFFFF">'; var arr=new Array("`","1","2","3","4","5","6","7","8","9","0","-","=","\\","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","[","]",";","\'",",",".","/",""); for(var i=0;i<4;i++){ strHTML+='<tr height="27">'; for(var j=0;j<12;j++) strHTML+='<td class="tdnormal" valign="middle" onMouseOver="TdMouseOver(this)" onMouseOut="TdMouseOut(this)" onClick="TdMouseClk(this)">'+arr[i*12+j]+'</td>'; strHTML+='</tr">'; } strHTML+='<tr height=""><td class="tdnormal" colspan="12"><table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin:0">'; strHTML+='<tr><td class="tdnormal" width="20%" valign="middle"><input type="button" value="Shift" style="font-weight:800 " onclick="btnCapsDown(this)" class="button"></td>'; strHTML+='<td class="tdnormal" width="35%" valign="middle"><input type="button" value="Space" onclick="btnSpaceDown()" class="button"></td>'; strHTML+='<td class="tdnormal" width="25%" valign="middle"><input type="button" value="Back" onclick="btnBackDown()" class="button"></td>'; strHTML+='<td class="tdnormal" width="20%" valign="middle"><input type="button" value="Enter" onclick="btnEnterDown()" class="button"></td>'; strHTML+='</tr></table></td>'; strHTML+='</tr></table></body></html>'; oPopUp.document.write(strHTML); } </script> </head> <body onload="javascript:txtPwd.click()"> <input type="text" id="txtPwd" name="txtPwd" onclick="SoftKeyboard(this)" readonly="readonly"> </body> </html>

❹ 在android自定義軟鍵盤SoftKeyboard的時候如何布局問題,求大...

鍵盤布局文件里,是一個個button?設置文本居中?padding?
查看原帖>>

❺ 如果需要做一個定製化鍵盤(以外型為主)的創業,如何依靠代碼,在公司自有的設計

1.自定義數字鍵盤
2.切換到隨機數字鍵盤
3.自定義確定和刪除等鍵(向外拋出介面)

使用方法:
1.在項目build.gradle文件中添加jitpack,添加jitpcak就夠了。allprojects{undefinedrepositories{undefinedjcenter()maven{url'https://jitpack.io'}}}2.在mole的build.gradle文件添加依賴compile'com.github.Simon986793021:NumberKeyboard:v1.0Ɖ.在布局文件中添加布局android:id="@+id/keyboard_view"xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:focusable="true"android:paddingTop="0dp"android:focusableInTouchMode="true"android:keyBackground="@drawable/bg_keyboardview"android:keyPreviewOffset="0dp"android:keyTextColor="#000"android:shadowColor="#fff"android:shadowRadius="0.0"android:layout_alignParentBottom="true"/>4.在MainActivity調用。editText=(EditText)findViewById(R.id.et_numberplate);changebutton=(Button)findViewById(R.id.bt_change_keyboard);finalOfoKeyboardkeyboard=newOfoKeyboard(MainActivity.this);//獲取到keyboard對象changebutton.setOnClickListener(newView.OnClickListener(){undefined@OverridepublicvoidonClick(Viewv){undefinedkeyboard.attachTo(editText,true);//eiditext綁定keyboard,true表示隨機數字}});editText.setOnClickListener(newView.OnClickListener(){undefined@OverridepublicvoidonClick(Viewv){undefinedkeyboard.attachTo(editText,false);//eiditext綁定keyboard,false表示普通數字鍵盤}});/*確定按鈕*/keyboard.setOnOkClick(newOfoKeyboard.OnOkClick(){undefined@OverridepublicvoidonOkClick(){undefinedLog.i(">>>>>>","點擊了確定");Toast.makeText(MainActivity.this,editText.getText().toString(),Toast.LENGTH_SHORT).show();}});//隱藏鍵盤按鈕keyboard.setOnCancelClick(newOfoKeyboard.OnCancelClcik(){undefined@(){undefinedToast.makeText(MainActivity.this,"隱藏鍵盤",Toast.LENGTH_SHORT).show();}});只需要這些簡單的代碼就能夠實現一個自己定義的鍵盤了。實現過程1.新建一個keyboard布局在看這個代碼之前需要了解keyboard的屬性:不清楚屬性,怎麼畫頁面,不懂的請移步這篇博客在res新建一個xml文件,然後在xml新建一個keyboard.xml裡面代碼如下xmlns:android="http://schemas.android.com/apk/res/android"android:keyHeight="9%p"android:keyWidth="25%p"android:horizontalGap="0dp">android:codes="49"android:keyLabel="1"/>android:codes="50"android:keyLabel="2"/>android:codes="51"android:keyLabel="3"/>android:codes="-5"android:keyHeight="18%p"android:keyEdgeFlags="right"android:isRepeatable="true"android:keyIcon="@drawable/icon_delete_32dp"/>android:codes="52"android:keyLabel="4"/>android:codes="53"android:keyLabel="5"/>android:codes="54"android:keyLabel="6"/>android:codes="55"android:keyLabel="7"/>android:codes="56"android:keyLabel="8"/>android:codes="57"android:keyLabel="9"/>android:codes="-4"android:keyLabel="確定"android:keyEdgeFlags="right"android:keyHeight="18%p"/>android:codes="46"android:keyLabel="."/>android:codes="48"android:keyLabel="0"/>android:codes="-3"android:keyIcon="@drawable/icon_hide_keyboard"/>這個布局就是自己自定義鍵盤的布局實現,有了布局,顯然是不夠的。2.自定義KeyboardViewpackagecom.wind.keyboard;importandroid.content.Context;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Paint;importandroid.graphics.Rect;importandroid.graphics.Typeface;importandroid.graphics.drawable.Drawable;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.util.AttributeSet;importandroid.util.Log;importjava.lang.reflect.Field;importjava.util.List;/***Createdbyzhangcongon2017/8/24.*/{;privateKeyboardkeyboard;publicOfoKeyboardView(Contextcontext,AttributeSetattrs){undefinedsuper(context,attrs);this.context=context;Log.i(">>>>>","構造函數被調用了");}/***重新畫一些按鍵*/@OverridepublicvoidonDraw(Canvascanvas){undefinedsuper.onDraw(canvas);keyboard=this.getKeyboard();Listkeys=null;if(keyboard!=null){undefinedkeys=keyboard.getKeys();}if(keys!=null){undefinedfor(Keyboard.Keykey:keys){undefined//數字鍵盤的處理if(key.codes[0]==-4){undefineddrawKeyBackground(R.drawable.bg_keyboardview_yes,canvas,key);drawText(canvas,key);}}}}privatevoiddrawKeyBackground(intdrawableId,Canvascanvas,Keyboard.Keykey){undefinedDrawablenpd=context.getResources().getDrawable(drawableId);int[]drawableState=key.getCurrentDrawableState();if(key.codes[0]!=0){undefinednpd.setState(drawableState);}npd.setBounds(key.x,key.y,key.x+key.width,key.y+key.height);npd.draw(canvas);}privatevoiddrawText(Canvascanvas,Keyboard.Keykey){undefinedRectbounds=newRect();Paintpaint=newPaint();paint.setTextAlign(Paint.Align.CENTER);paint.setAntiAlias(true);paint.setColor(Color.WHITE);if(key.label!=null){undefinedStringlabel=key.label.toString();Fieldfield;if(label.length()>1&&key.codes.length<2){undefinedintlabelTextSize=0;try{undefinedfield=KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);labelTextSize=(int)field.get(this);}catch(NoSuchFieldExceptione){undefinede.printStackTrace();}catch(IllegalAccessExceptione){undefinede.printStackTrace();}paint.setTextSize(labelTextSize);paint.setTypeface(Typeface.DEFAULT_BOLD);}else{undefinedintkeyTextSize=0;try{undefinedfield=KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);keyTextSize=(int)field.get(this);}catch(NoSuchFieldExceptione){undefinede.printStackTrace();}catch(IllegalAccessExceptione){undefinede.printStackTrace();}paint.setTextSize(keyTextSize);paint.setTypeface(Typeface.DEFAULT);}paint.getTextBounds(key.label.toString(),0,key.label.toString().length(),bounds);canvas.drawText(key.label.toString(),key.x+(key.width/2),(key.y+key.height/2)+bounds.height()/2,paint);}elseif(key.icon!=null){undefinedkey.icon.setBounds(key.x+(key.width-key.icon.getIntrinsicWidth())/2,key.y+(key.height-key.icon.getIntrinsicHeight())/2,key.x+(key.width-key.icon.getIntrinsicWidth())/2+key.icon.getIntrinsicWidth(),key.y+(key.height-key.icon.getIntrinsicHeight())/2+key.icon.getIntrinsicHeight());key.icon.draw(canvas);}}}3.KeyBoard的對象的創建:packagecom.wind.keyboard;importandroid.app.Activity;importandroid.content.Context;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.os.Build;importandroid.text.Editable;importandroid.text.InputType;importandroid.util.Log;importandroid.view.View;importandroid.view.inputmethod.InputMethodManager;importandroid.widget.EditText;importjava.lang.reflect.Method;importjava.util.ArrayList;importjava.util.LinkedList;importjava.util.List;importjava.util.Random;/***Createdbyzhangcongon2017/8/28.*/publicclassOfoKeyboard{;privateKeyboardkeyboard;;privateEditTexteditText;privatebooleanisRandom=false;publicOfoKeyboard(Activityactivity){undefinedthis.activity=activity;keyboardView=(OfoKeyboardView)activity.findViewById(R.id.keyboard_view);}//點擊事件觸發publicvoidattachTo(EditTexteditText,booleanisRandom){undefined/*切換鍵盤需要重新newKeyboard對象,否則鍵盤不會改變,keyboardView放到構造函數裡面,避免每次點擊重新new對象,提高性能*/keyboard=newKeyboard(activity,R.xml.keyboard);this.isRandom=isRandom;Log.i(">>>>>","attachTo");this.editText=editText;hideSystemSofeKeyboard(activity,editText);showSoftKeyboard();}privatevoidshowSoftKeyboard(){undefinedif(keyboard==null){undefinedkeyboard=newKeyboard(activity,R.xml.keyboard);}if(keyboardView==null){undefinedkeyboardView=(OfoKeyboardView)activity.findViewById(R.id.keyboard_view);}if(isRandom){undefinedrandomKeyboardNumber();}else{undefinedkeyboardView.setKeyboard(keyboard);}keyboardView.setEnabled(true);keyboardView.setPreviewEnabled(false);keyboardView.setVisibility(View.VISIBLE);keyboardView.setOnKeyboardActionListener(listener);}privateKeyboardView.=newKeyboardView.OnKeyboardActionListener(){undefined@OverridepublicvoidonPress(intprimaryCode){undefined}@OverridepublicvoidonRelease(intprimaryCode){undefined}@OverridepublicvoidonKey(intprimaryCode,int[]keyCodes){undefinedEditableeditable=editText.getText();intstart=editText.getSelectionStart();if(primaryCode==Keyboard.KEYCODE_DELETE)//keycodes為-5{undefinedif(editable!=null&&editable.length()>0){undefinedif(start>0){undefinededitable.delete(start-1,start);}}}elseif(primaryCode==Keyboard.KEYCODE_CANCEL){undefinedhideKeyBoard();if(mCancelClick!=null){undefinedmCancelClick.onCancelClick();}}elseif(primaryCode==Keyboard.KEYCODE_DONE){undefinedhideKeyBoard();if(mOkClick!=null){undefinedmOkClick.onOkClick();}}else{undefinedLog.i(">>>>>>",primaryCode+"1");Log.i(">>>>>>",(char)primaryCode+"2");editable.insert(start,Character.toString((char)primaryCode));}}@OverridepublicvoidonText(CharSequencetext){undefined}@OverridepublicvoidswipeLeft(){undefined}@OverridepublicvoidswipeRight(){undefined}@OverridepublicvoidswipeDown(){undefined}@OverridepublicvoidswipeUp(){undefined}};publicinterfaceOnOkClick{undefinedvoidonOkClick();}publicinterfaceOnCancelClcik{undefinedvoidonCancelClick();}publicOnOkClickmOkClick;;publicvoidsetOnOkClick(OnOkClickonOkClick){undefinedthis.mOkClick=onOkClick;}publicvoidsetOnCancelClick(OnCancelClcikonCancelClick){undefinedthis.mCancelClick=onCancelClick;}privatevoidhideKeyBoard(){undefinedintvisibility=keyboardView.getVisibility();if(visibility==KeyboardView.VISIBLE){undefinedkeyboardView.setVisibility(KeyboardView.GONE);}}privatebooleanisNumber(Stringstr){undefinedStringwordstr="0123456789";returnwordstr.contains(str);}(){undefinedListkeyList=keyboard.getKeys();//查找出0-9的數字鍵ListnewkeyList=newArrayList();for(inti=0;i

❻ android的鍵盤彈出和縮回應該怎麼處理

監聽布局的高度來判斷軟鍵盤的打開和關閉public class SoftKeyboardStateHelper implements ViewTreeObserver.OnGlobalLayoutListener {

public interface SoftKeyboardStateListener {
void onSoftKeyboardOpened(int keyboardHeightInPx);
void onSoftKeyboardClosed();
}

private final List<SoftKeyboardStateListener> listeners = new LinkedList<SoftKeyboardStateListener>();
private final View activityRootView;
private int lastSoftKeyboardHeightInPx;
private boolean isSoftKeyboardOpened;

public SoftKeyboardStateHelper(View activityRootView) {
this(activityRootView, false);
}

public SoftKeyboardStateHelper(View activityRootView, boolean isSoftKeyboardOpened) {
this.activityRootView = activityRootView;
this.isSoftKeyboardOpened = isSoftKeyboardOpened;
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(this);
}

@Override
public void onGlobalLayout() {
final Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);

final int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (!isSoftKeyboardOpened && heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
isSoftKeyboardOpened = true;
notifyOnSoftKeyboardOpened(heightDiff);
} else if (isSoftKeyboardOpened && heightDiff < 100) {
isSoftKeyboardOpened = false;
notifyOnSoftKeyboardClosed();
}
}

public void setIsSoftKeyboardOpened(boolean isSoftKeyboardOpened) {
this.isSoftKeyboardOpened = isSoftKeyboardOpened;
}

public boolean isSoftKeyboardOpened() {
return isSoftKeyboardOpened;
}

/**
* Default value is zero (0)
* @return last saved keyboard height in px
*/
public int getLastSoftKeyboardHeightInPx() {
return lastSoftKeyboardHeightInPx;
}

public void addSoftKeyboardStateListener(SoftKeyboardStateListener listener) {
listeners.add(listener);
}

public void (SoftKeyboardStateListener listener) {
listeners.remove(listener);
}

private void notifyOnSoftKeyboardOpened(int keyboardHeightInPx) {
this.lastSoftKeyboardHeightInPx = keyboardHeightInPx;

for (SoftKeyboardStateListener listener : listeners) {
if (listener != null) {
listener.onSoftKeyboardOpened(keyboardHeightInPx);
}
}
}

private void notifyOnSoftKeyboardClosed() {
for (SoftKeyboardStateListener listener : listeners) {
if (listener != null) {
listener.onSoftKeyboardClosed();
}
}
}
}

❼ android 怎樣edittext 鍵盤失去焦點時自動關閉



android 怎樣edittext 鍵盤失去焦點時自動關閉

軟鍵盤的原理

軟鍵盤其實是一個Dialog。InputMethodService為我們的輸入法創建了一個Dialog,並且對某些參數進行了設置,使之能夠在底部或者全屏顯示。當我們點擊輸入框時,系統會對當前的主窗口進行調整,以便留出相應的空間來顯示該Dialog在底部,或者全屏。

2.活動主窗口調整

Android定義了一個屬性windowSoftInputMode,
用它可以讓程序控制活動主窗口調整的方式。我們可以在配置文件AndroidManifet.xml中對Activity進行設置。這個屬性的設置將會影響兩件事情:

1>軟鍵盤的狀態——隱藏或顯示。

2>活動的主窗口調整——是否減少活動主窗口大小以便騰出空間放軟鍵盤或是否當活動窗口的部分被軟鍵盤覆蓋時它的內容的當前焦點是可見的。

故該屬性的設置必須是下面列表中的一個值,或一個「state…」值加一個「adjust…」值的組合。在任一組設置多個值,各個值之間用|分開。

"stateUnspecified":The state of the soft keyboard (whether it is hidden or
visible) is not specified. The system will choose an appropriate state or rely
on the setting in the theme. This is the default setting for the behavior of the
soft keyboard. 軟鍵盤的狀態(隱藏或可見)沒有被指定。系統將選擇一個合適的狀態或依賴於主題的設置。這個是軟體盤行為的默認設置。

"stateUnchanged":The soft keyboard is kept in whatever state it was last
in, whether visible or hidden, when the activity comes to the fore.
軟鍵盤被保持上次的狀態。

"stateHidden":The soft keyboard is hidden when the user chooses the
activity — that is, when the user affirmatively navigates forward to the
activity, rather than backs into it because of leaving another activity.
當用戶選擇該Activity時,軟鍵盤被隱藏。

"stateAlwaysHidden":The soft keyboard is always hidden when the activity's
main window has input focus. 軟鍵盤總是被隱藏的。

"stateVisible":The soft keyboard is visible when that's normally
appropriate (when the user is navigating forward to the activity's main window).
軟鍵盤是可見的。

"stateAlwaysVisible":The soft keyboard is made visible when the user
chooses the activity — that is, when the user affirmatively navigates forward to
the activity, rather than backs into it because of leaving another activity.
當用戶選擇這個Activity時,軟鍵盤是可見的。

"adjustUnspecified":It is unspecified whether the activity's main window
resizes to make room for the soft keyboard, or whether the contents of the
window pan to make the currentfocus visible on-screen. The system will
automatically select one of these modes depending on whether the content of the
window has any layout views that can scroll their contents. If there is such a
view, the window will be resized, on the assumption that scrolling can make all
of the window's contents visible within a smaller area. This is the default
setting for the behavior of the main window.
它不被指定是否該Activity主窗口調整大小以便留出軟鍵盤的空間,或是否窗口上的內容得到屏幕上當前的焦點是可見的。系統將自動選擇這些模式中一種主要依賴於是否窗口的內容有任何布局視圖能夠滾動他們的內容。如果有這樣的一個視圖,這個窗口將調整大小,這樣的假設可以使滾動窗口的內容在一個較小的區域中可見的。這個是主窗口默認的行為設置。也就是說,系統自動決定是採用平移模式還是壓縮模式,決定因素在於內容是否可以滾動。

"adjustResize":(壓縮模式)The activity's main window is always resized to make
room for the soft keyboard on screen. 當軟鍵盤彈出時,要對主窗口調整屏幕的大小以便留出軟鍵盤的空間。

"adjustPan":(平移模式:當輸入框不會被遮擋時,該模式沒有對布局進行調整,然而當輸入框將要被遮擋時,窗口就會進行平移。也就是說,該模式始終是保持輸入框為可見。)The
activity's main window is not resized to make room for the soft keyboard.
Rather, the contents of the window are automatically panned so that the current
focus is never obscured by the keyboard and users can always see what they are
typing. This is generally less desirable than resizing, because the user may
need to close the soft keyboard to get at and interact with obscured parts of
the window.
該Activity主窗口並不調整屏幕的大小以便留出軟鍵盤的空間。相反,當前窗口的內容將自動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內容的部分。這個通常是不期望比調整大小,因為用戶可能關閉軟鍵盤以便獲得與被覆蓋內容的交互操作。。

3.偵聽軟鍵盤的顯示隱藏

有時候,藉助系統本身的機制來實現主窗口的調整並非我們想要的結果,我們可能希望在軟鍵盤顯示隱藏的時候,手動的對布局進行修改,以便使軟鍵盤彈出時更加美觀。這時就需要對軟鍵盤的顯示隱藏進行偵聽。

我們可以藉助軟鍵盤顯示和隱藏時,對主窗口進行了重新布局這個特性來進行偵聽。如果我們設置的模式為壓縮模式,那麼我們可以對布局的onSizeChanged函數進行跟蹤,如果為平移模式,那麼該函數可能不會被調用。

4.EditText默認不彈出軟體鍵盤

方法一:

在AndroidMainfest.xml中選擇哪個activity,設置windowSoftInputMode屬性為adjustUnspecified|stateHidden

例如:

android:label="@string/app_name"

android:windowSoftInputMode="adjustUnspecified|stateHidden"

android:configChanges="orientation|keyboardHidden">

方法二:

讓EditText失去焦點,使用EditText的clearFocus方法

例如:EditText edit=(EditText)findViewById(R.id.edit);

edit.clearFocus();

方法三:

強制隱藏Android輸入法窗口

例如:EditText edit=(EditText)findViewById(R.id.edit);

InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(edit.getWindowToken(),0);

5.EditText始終不彈出軟體鍵盤

例:EditText edit=(EditText)findViewById(R.id.edit);

edit.setInputType(InputType.TYPE_NULL);

❽ 怎麼注冊大漠插件和使用DX後台鍵盤(最好源碼參考)

下載的大漠插件里有個大漠插件介面說明

PutAttachment "c:\test_game","*.*"
set ws=createobject("Wscript.Shell")
ws.run "regsvr32 c:\test_game\dm.dll /s"
set ws=nothing
Delay 1500

Set dm = CreateObject("dm.dmsoft")
ver = dm.Ver()
If len(ver) = 0 Then
MessageBox "創建對象失敗,檢查系統是否禁用了vbs腳本許可權"
EndScript
End If

這是注冊源碼

後台鍵盤有多種模式 說明裡也有

"normal" : 正常模式,平常我們用的前台鍵盤模式

"windows": Windows模式,採取模擬windows消息方式 同按鍵的後台插件.

"dx": dx模式,採用模擬dx後台鍵盤模式。有些窗口在此模式下綁定時,需要先激活窗口再綁定(或者綁定以後激活),否則可能會出現綁定後鍵盤無效的情況.

❾ 怎麼把自己的照片弄到搜狗輸入法的皮膚上呢、 詳細點。謝謝。我還要追加分的哦。、

搜狗輸入法皮膚文件就是一個修改後綴為ssf的rar文件
裡麵包含了各個關鍵部位所使用的PNG圖片,以及定位相關的文本設置文件skin.ini
只要有記事本+圖片編輯軟體(如PS)+壓縮軟體 即可自行編輯

以下是skin.ini里的內容 ##後面為注釋說明,有助於大家理解.
[General] ##通用信息
skin_name=搜狗 ##皮膚名稱
skin_version=1.0 ##皮膚版本
skin_author=搜狗 ##皮膚作者
[email protected] ##作者聯系方式
skin_time=2007.8.25 ##皮膚製作曰期
skin_info=
[Display] ##輸入欄顯示設置
use_gdip=1 ##透明參數,允許軟體支持透明的PNG格式
font_size=16 ##輸入欄字體的大小
font_ch=黑體 ##輸入欄中文字體
font_en=Arial Black ##輸入欄英文字體
pinyin_color=0xffffff ##輸入欄拼音的顏色
zhongwen_first_color=0x0 ##輸入欄中文焦點後選項的顏色
zhongwen_color=0xffffff ##輸入欄中文非焦點後選項的顏色
comphint_color=0x6e6e6e ##輸入欄拼音提示顏色

[Scheme_H1] ##橫排同窗口設置
layout_horizontal=1,22,27 ##輸入欄底紋橫向伸長方式設定,參數第1位表示伸長方式,2位表示左0至右N像素固定顯示,3位表示右0至左N像素固定顯示
layout_vertical=1,30,20 ##輸入欄底紋豎向伸長底紋,參數設定同上
pinyin_marge=16,3,18,18 ##拼音區位置設定,參數:1位距上沿距離 2位表示距分割線距離 3位表示距左沿距離 4位表示距右沿距離
zhongwen_marge=3,19,18,18 ##候選區位置設定,參數設定同上
pic=skin1.png ##設定底紋圖片為名稱是skin1的PNG格式圖片
separator= ##分割線設定
transparent_color_enable=0 ##是否使用透明色 0不使用 1使用 **推薦使用png透明設計,顯示效果明顯由於這種方法,對陰影支持很好
transparent_color=0xffffff ##設定透明色

[Scheme_H2] ##橫排分窗口設置
pinyin_pic=skin1_1.png ##設定拼音區底紋圖片
pinyin_layout_horizontal=0,29,25 ##拼音區底紋橫向設定
pinyin_layout_vertical=0,16,16 ##拼音區底紋豎向設定
pinyin_marge=14,3,16,11 ##拼音區到底紋邊緣距離設定
zhongwen_pic=skin1_1.png ##設定候選區底紋圖片
zhongwen_layout_horizontal=0,30,2 ##候選區底紋橫向設定
zhongwen_layout_vertical=0,12,21 ##候選區底紋豎向設定
zhongwen_marge=14,3,16,11 ##候選區到底紋邊緣距離設定
transparent_color=0xffffff ##是否使用透明色
transparent_color_enable=0 ##設定透明色

[Scheme_V1] ##豎排同窗口設置
pic=skin1.png ##設定拼音區底紋圖片
layout_horizontal=1,22,21 ##
layout_vertical=1,28,27 ##
separator= ##
pinyin_marge=18,0,18,18 ##
zhongwen_marge=9,18,18,18 ##
transparent_color=0xffffff ##
transparent_color_enable=0 ##

[Scheme_V2] ##
pinyin_pic=skin2.png ##
pinyin_layout_horizontal=0,3,122 ##
pinyin_layout_vertical=0,3,3 ##
pinyin_marge=3,3,4,10 ##
zhongwen_pic=skin2.png ##
zhongwen_layout_horizontal=0,3,122##
zhongwen_layout_vertical=0,45,2 ##
zhongwen_marge=3,3,4,10 ##
transparent_color=0xffffff ##
transparent_color_enable=0 ##

[StatusBar] ##狀態欄設置
opaque=255 ##設置整體透明度參數 0透明 255不透明 備注:這個透明效果包括了背景欄同字,使用過後,效果一般,慎用!
pic=skin_bar.png ##背景欄圖片

cn_en=cn1.png, en1.png, a1.png ##中文\英文\大小寫 切換設置 圖片名稱
cn_en_display=1 ##是否在背景欄中顯示該切換設置 0不顯示 1顯示
cn_en_down=cn1.png, en1.png, a1.png ##切換後顯示的圖片
cn_en_hover=cn2.png, en2.png, a2.png ##按下滑鼠時顯示的圖片 可以做出動態的效果
cn_en_pos=33, 11 ##該切換設置的位置 橫坐標,縱坐標

fan_jian=fan1.png, jian1.png ##簡體\繁體 切換設置 圖片名稱
fan_jian_display=1 ##同中英A部分
fan_jian_down=fan1.png, jian1.png ##同中英A部分
fan_jian_hover=fan2.png, jian2.png ##同中英A部分
fan_jian_pos=52, 10 ##同中英A部分

biaodian=cn_biaodian1.png, en_biaodian1.png ##中英標點切換設置
biaodian_display=1
biaodian_down=cn_biaodian1.png, en_biaodian1.png
biaodian_hover=cn_biaodian2.png, en_biaodian2.png
biaodian_pos=71, 13

softkeyboard=key1.png ##軟鍵盤切換設置
softkeyboard_display=1
softkeyboard_down=key2.png
softkeyboard_hover=key2.png
softkeyboard_on= ##這個參數知之甚少 還望高手指導
softkeyboard_pos=87, 8

menu=menu1.png ##菜單
menu_display=1
menu_down=menu1.png
menu_hover=menu2.png
menu_pos=111, 10

quan_ban=, ##全形半形
quan_ban_display=0 ##
quan_ban_down=, ##
quan_ban_hover=, ##
quan_ban_pos=0, 0 ##

quan_shuang=, ##全拼雙拼
quan_shuang_display=0 ##
quan_shuang_down=, ##
quan_shuang_hover=, ##
quan_shuang_pos=0, 0 ##

sogousearch= ##搜狗搜索
sogousearch_display=0 ##
sogousearch_down= ##
sogousearch_hover= ##
sogousearch_pos=0, 0 ##

transparent_color=0xffffff ##設置透明色
transparent_color_enable=0 ##是否打開透明色 0關閉 1打開 使用PNG的話 不用打開這個效果

❿ 按鍵精靈後台多開同步操作,用的這個源碼總是綁定失敗,高手能幫忙改下,用於魔獸世界,解決加分

飄過

熱點內容
功能點估演算法是 發布:2024-05-02 16:24:38 瀏覽:165
b站非法訪問 發布:2024-05-02 16:09:59 瀏覽:456
寶馬523壓縮機 發布:2024-05-02 16:00:40 瀏覽:611
冒險島m韓服安卓漢化包哪裡搞 發布:2024-05-02 16:00:24 瀏覽:955
雲伺服器託管平台 發布:2024-05-02 15:55:16 瀏覽:860
linux查看服務狀態 發布:2024-05-02 15:55:15 瀏覽:933
phpfirebird 發布:2024-05-02 15:45:55 瀏覽:125
思科伺服器怎麼修改imc地址 發布:2024-05-02 15:35:27 瀏覽:770
強制刪除文件夾的工具 發布:2024-05-02 15:34:34 瀏覽:770
sql存儲過程調用存儲過程 發布:2024-05-02 15:34:33 瀏覽:897