当前位置:首页 » 操作系统 » 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-17 10:17:00 浏览:752
抖音引流脚本推荐 发布:2024-05-17 10:11:16 浏览:724
sql数据库数据路径 发布:2024-05-17 10:00:25 浏览:132
ftp服务器程序 发布:2024-05-17 10:00:21 浏览:677
php中的函数 发布:2024-05-17 09:53:34 浏览:941
优质网站为什么用ip服务器 发布:2024-05-17 09:43:34 浏览:793
安卓机图片存在哪里 发布:2024-05-17 09:42:54 浏览:62
ip地址怎么查看服务器上的文件 发布:2024-05-17 09:29:51 浏览:980
轱轮算法 发布:2024-05-17 09:29:10 浏览:96
安卓手机锁屏密码一般怎么画 发布:2024-05-17 09:29:05 浏览:348