hardware keyboard hooks - Xposed General

Hi
I have some experience in android development, now trying myself in xposed modules. Sorry if i missed the newbie thread - couldn't find it.
The question is - how to get all key events for hardware keyboard. Solution would be nice, but some pushes in right direction is fine too.
The idea is - make hotkey control for some application-specific actions (which isquite useful for android tv boxs).

hoanggia11 said:
Hi
I have some experience in android development, now trying myself in xposed modules. Sorry if i missed the newbie thread - couldn't find it.
The question is - how to get all key events for hardware keyboard. Solution would be nice, but some pushes in right direction is fine too.
The idea is - make hotkey control for some application-specific actions (which isquite useful for android tv boxs).
Click to expand...
Click to collapse
Keys presses are handled in InputManagerService.
You can e.g. try hooking onto dispatchUnhandledKey which is called in case current app did not handle a key event itself.
Check more detailed description here: https://android.googlesource.com/pl...va/android/view/WindowManagerPolicy.java#1126
If you want your functionality triggered only for a certain app you will have to ensure that win parameter (window that has focus) is that app before executing your action.

Related

Rewrite button driver

I was wondering, would it be feasible to rewrite the button driver to customize the X1 buttons? I mean even higher level than a key hook. Key hooks are annoying because they interfere with other apps that want to set key hooks. Hot keys are useful, but another application can come along and steal your hotkey. I want to modify the X1 buttons at a much higher level.
One thing for instance about the panel button i have always wanted to know. The panel manager sends out button code 0x00EA. Even if this event is suppressed by a key hook, the panel manager still opens. So I wonder what part of the OS is responsible for this? Is there a button driver dll that can be overwritten? Is the button driver built into the OEMXipKernel (but possibly overwrite-able at the ROM cooking level)?
Basically I want to know if it is possible to rewrite the button driver that actually detects the hardware interrupts from the keyboard/buttons and sends key press events to the OS. Does anyone know if this is possible? People have rewritten/modified things such as the battery and even display drivers. Is this in the same category?
yes there is keboard dll
keypad.dll it "supports" panel manager button, ok, arrows & everything else...
if U could write something like thi, it would be great... i think... I'm maniac of very useful Xperia buttons (there is no other device like sex1, which has so many buttons on front panel... ! it's just great !)
giving users possibility to bind actions (win lock, new process, win key, esc, ok, OK/Close, back, home, etc... to any ! button would be great !), swapping, changing them, different actions for different screens ... GREAT !! I can see !!
I was thinking long time ago about doing such of thing but has no idea how to modify existing keypad.dll (no such great programmer skills) or create new one but in "low level type" ... (interfacing hardware ? :/ noooo idea... ! )
If You'd like my help i could create advanced GUI Configurator of program...
cichy3000 said:
yes there is keboard dll
keypad.dll it "supports" panel manager button, ok, arrows & everything else...
if U could write something like thi, it would be great... i think... I'm maniac of very useful Xperia buttons (there is no other device like sex1, which has so many buttons on front panel... ! it's just great !)
giving users possibility to bind actions (win lock, new process, win key, esc, ok, OK/Close, back, home, etc... to any ! button would be great !), swapping, changing them, different actions for different screens ... GREAT !! I can see !!
I was thinking long time ago about doing such of thing but has no idea how to modify existing keypad.dll (no such great programmer skills) or create new one but in "low level type" ... (interfacing hardware ? :/ noooo idea... ! )
If You'd like my help i could create advanced GUI Configurator of program...
Click to expand...
Click to collapse
Yes it really annoys me that manufacturers dont like to let you modify buttons anymore. I wrote X1BC to modify the buttons but I am tired of higher level methods of trapping keys. I want to go straight to the source.
Let me start taking a look at keypad.dll. I see in my ROM kitchen that it exists as a file (not a module) in OEM drivers. I want to see what the effect of cooking a ROM without it is. Also I will look at references to it in the registry and try to examine dll exports (going to google for software to do this; any free PE analyzers?).
So keypad.dll imports coredll.dll and ossvcs.dll. It exports KBD_Close, KBD_Deinit, KBD_IOControl, KBD_Init, KBD_Open, KBD_PowerDown, and KBD_PowerUp. I dont know what parameters those functions should take though. I want to write a keypad.dll and replace the old one to see when these functions are called.
Found this:
http://read.pudn.com/downloads120/sourcecode/embed/511498/HID/CLIENTS/KBDHID/kbd.cpp__.htm
i cross my fingers... thats sounds great... maybe you can little inspire from X2 keyboard layout maybe dll...
Well.. I dont have an X2 to test that with. :-/
Before I can start experimenting with overwriting the keyboard driver, I need to know how to properly sign drivers. I know that without being signed properly a driver will cause the device not to boot. Can someone tell me how I sign my home cooked driver?
*edit*
Well, keypad.dll doesnt seem to be the low level *driver*. Its just a service. Found this by searching keypad.dll into my kitchen:
Code:
[HKEY_LOCAL_MACHINE\Services\Keypad]
"Prefix"="KBD"
"Dll"="keypad.dll"
"Index"=dword:1
"Order"=dword:15
"Flags"=dword:00010000 ; DEVFLAGS_TRUSTEDCALLERONLY
"DisableKeyLight"=dword:0
"DisableGhostKeyDetect"=dword:0
"ActionDebounceTimeout"=dword:64 ; 100ms
So perhaps my dll doesnt need to signed. I dont even need to replace the old dll. Just point it to my own dll. I just changed "Dll"= to something else and rebooted. Device boots just fine but now the buttons do nothing. Good sign .
some time ago I've accidentally replaced HTC Diamond keypad.dll with Xperia's one (well... i didn't know that with cab that I made, was included keypad.dll didn't notice that ) ... the only issue that came after this change was "no keyboard effect", after I installed one more time the dll but with the right one... the issue gone ...
Just as interesting for what's new? Sorry for my curiosity ... Thank you
I have only done basic experimentation so far. First changed keypad.dll to something else in the registry (something that didnt exist) and as expected the buttons stopped working. I have written a dll to replace it that exports the same functions and made it log every time a function is called. I get attached to many processes and receive some calls to KBD_Init and KBD_IOControl. Nothing in particular corresponds with when a button is pushed yet, but that is probably because I need to respond to KBD_Init by initializing the keyboard. Have not been able to work on it for a while but hopefully I will next week, as I am on winter break from school. Thanks for your interest!
Jon
so we have (via Dependency Walker ):
KBD_Close
KBD_Deinit
KBD_IOControl
KBD_Init
KBD_Open
KBD_PowerDown
KBD_PowerUp
and we don't know how to use them (what arguments to use)... so what can we do with it ? guessing parameters ?
cichy3000 said:
so we have (via Dependency Walker ):
KBD_Close
KBD_Deinit
KBD_IOControl
KBD_Init
KBD_Open
KBD_PowerDown
KBD_PowerUp
and we don't know how to use them (what arguments to use)... so what can we do with it ? guessing parameters ?
Click to expand...
Click to collapse
Look at the link in post 5. Hopefully they are the same. What I am going to do next when I have time is understand that code.
So it looks like those are just the standard exported functions necessary for a service dll. The real meat of what the dll does probably has nothing to do with them. What I need to know is how to recieve keypress info from the keyboard driver and how to inject key events into the OS. Can I just use keybd_event funtion to send key events?..
Looks like I found an answer to that. From MSDN:
http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx
The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
Is keypad.dll the interrupt handler? Or is that something else? It must be. Because if I kill the keypad service no button events get through. I dont see how missing that service would kill the keybd_event function. Off to experiment.
If keybd_event proves to be the correct way to send key events the last question is how to receive interrupts from the keyboard.
I have learned loads over the past day. I Now fully understand the role of keypad.dll it must register to receive the interrupt and use keybd_event to sent keys to the OS. Through disassembly of keypad.dll I have also learned that this role is not simple. This dll has a LOT of code. I dont think I will be able to reproduce everything it does.
I have a new idea however. All I need to do is intercept calls from keypad.dll and decide what to really send and call keybd_event myself. I still achieve the goal of catching key events before 3rd party apps. I can think of two ways to achieve this. One would be to patch keypad.dll to call my own routine instead of keybd_event. Another would by to leave the stock keypad.dll and hook the keybd_event API at runtime. While I have learned loads at how to disassemble dlls and read the assembly, I do not yet know how to modify the import table. On the flipside I do not fully know how to hook APIs. Any help? I would like to go the modify import table route as this seems infinitely simpler.
keyboard driver successfully hooked.
The most reliable button reprogrammer is under way.
Program in private beta.
http://forum.xda-developers.com/showthread.php?p=5272353

Function keymap for BT keyboard on Galaxy Tab

Hi, Gurus:
Not sure this is the right forum, but since this tends to be the more techie-centric area, I thought I'd try here.
I support a number of systems that are mainframe- or AS/400-based, and these systems rely heavily on function keys and special keys not necessarily common to Android system. I am trying to understand what changes I need to make to /system/usr/keylayout/my_device.kl in order to get my_device to properly process, say, function key keystrokes.
I have been unable to locate the values I need on either side of the equation (scan code vs. what gets sent). Any advice from members here?
Thanks!
Dennis
Sent from my GT-P1000 using XDA Premium App

Bluetooth keyboard, mouse and orientation

I went out and grabbed a Microsoft Bluetooth Portable 6000 keyboard, which is fantastic, by the way. I purchased it with the sole purpose of using it with CM7 w/Bluetooth and aDOSBox. Yeah, I want to kick it old school.
First, when in landscape mode, it will not reorient the arrow keys. Up arrow is left, Left arrow is down and so forth. This is simply the keyboard not being remapped when orientation changes, however... I'm not seeing a simple way to compensate for this.
Any thoughts?
Also, I'm tempted to see what a Bluetooth mouse does on this. I'm finding that the keystroke standards in Android don't follow normal "Windows and clones" methodology. So, having to reach up and touch the screen displaces you enough to make it inconvenient to perform certain tasks.
Is there a proper mouse implementation either in Android or in the CM7 stack? If not, are they any APKs that would satisfy this?
I'm looking for a laptop replacement, if you get the gist of what I'm trying to do here. I want to be able to type a book on a Nook.
Ironic, eh?
I don't think android has the ability to change the key mappings based on orientation.. you might be able to write an app that would do this though. The easiest way to do this is to have to key maps and have your app switch between them when it detects and orientation change. That might not be very efficient but it would be fairly simple to write, I think.
As for the mouse, I can't comment on using it with the nook but I have used a bt mouse with other android devices and it works fine. It would just as you would expect.
I bought also a chinese flexible BT keyboard but has some lag sometimes.
Remapping of keys would interest me also.
There is a fix for the rotation problem. Also for getting the "<" and ">" buttons working. Search isn't working for me and i don't feel like manually combing the forums for it, but it's in a thread labelled "chisleu's mod" or something like that.
edit, found the link:
http://forum.xda-developers.com/showthread.php?t=1008612
I'm going to try this out. This is likely exactly what I'm looking for. I don't expect to use the keyboard in portrait mode... I'll let everyone know how it works for me.
I will eventually be cool enough to write something like this myself, but until then... Script Kiddie, AWAY!

Remix player no hardware keyboard support?

I have downloaded and run Remix OS Player on two different computers now and neither one of them has captured my hardware keyboard, I can use the onscreen keyboard but that really lessens the functionality and is half the point of having it run on a desktop. Can anyone advise as to how to resolve this issue? The options, advanced options, and the OS options are so dummy proofed it is impossible to do anything advanced. Is there config files I can edit or...?
I had this happen once right after installation and running the Google Play Store activator and couldn't login in to the Play Store because I couldn't type on the physical keyboard. I shutdown the player, restarted it, and then the problem went away. Might work for you.
Hi.
I have this too, regardless if I restart or not. I actually can't figure out what I have to change in language and imput options to have my keyboard back. The only thing I can do is using the virtual keyboard. I think this happened when I changed the language to french, or tried the virtual keyboard for the first time before then deactivating it. Since I can't find a reset config to default, I'm going to reinstall.
If anyone have a guess how getting my azerty hardware keyboard back, could he please explain ? I find the way the multiple language/imput options are displayed isn't very clear and whatever I do it doesn't work. I'm visibly not alone since this thread is already open, and it may be useful.
Edit : looks like the config files are not in the remix folder. After new installation in different folder, it's directly the same with the new separated machine.
dzeek said:
I had this happen once right after installation and running the Google Play Store activator and couldn't login in to the Play Store because I couldn't type on the physical keyboard. I shutdown the player, restarted it, and then the problem went away. Might work for you.
Click to expand...
Click to collapse
There never was any actual ability to use the physical keyboard even though the settings say it's present. No amount of fiddling with the unintuitive settings seems to correct the problem. My keyboard is a Saitek Eclipse USB keyboard on Windows 7 x64. I imagine this must be a limitation of the emulator or some basic setting. The two systems I have run this on are very similar setups with the exception that the other one uses a PS2 mouse and keyboard. Shortcuts like CTRL + ALT to unbind keyboard and mouse function normally so why not typing inside the emulator?
Saiber77 said:
There never was any actual ability to use the physical keyboard even though the settings say it's present. No amount of fiddling with the unintuitive settings seems to correct the problem. My keyboard is a Saitek Eclipse USB keyboard on Windows 7 x64. I imagine this must be a limitation of the emulator or some basic setting. The two systems I have run this on are very similar setups with the exception that the other one uses a PS2 mouse and keyboard. Shortcuts like CTRL + ALT to unbind keyboard and mouse function normally so why not typing inside the emulator?
Click to expand...
Click to collapse
I don't understand. Are you saying you have never been able to use your computer's keyboard ? Well sorry, you already said it sooner too. I didn't read it was the same person.
The thing is I could use it till two days ago, and I'm not the only one. I could type the physical keyboard at first start of the player without doing anything, it was default. Then probably messed up with the options I touched and can't have it back. RemixOS live or hardware installed have the keyboard detected and used as default. So does the player (except maybe you but it must just be that your keyboard isn't recognized or I don't know what.
Detection and options problem here. No lack in feature like I understand you are thinking.
I am saying that there has been not one moment I could use my computer's physical keyboard in Remix OS player, not for the very first initial run nor extracting it to a different folder, it works just fine on both computers for Windows use though. I am using the PS2 keyboard as I type this... I wouldn't think it would be difficult for the player to bind to a generic Human Interface Device or a USB keyboard... Both Mice work just fine so I figure it's just a bad config file or something. Hopefully someone figures it out soon as it's annoying to say the least.
Since I had it then lost it. Could one user or more, whose physical keyboard works since the beginning and who never changed anything to default config, screen all his/their language/keyboard relater configs please ? This may do.
Guess they don't care... oh well... Nox it is.
If this can help some people forced to use virtual keyboard too. After looking for a suitable virtual keyboard, I ended using Minuum Keyboard and Hacker's Keyboard app. The first takes the less place possible, and the 2nd looks like it has the better ratio between space used and easy access to all keys (it's sort of computer keyboard replica) ... waiting for this issue resolve if it is resolved a day, this will sorta do the trick ... But the problem really sucks.
@Saiber77 @dzeek @Esdeve - Sorry to be late with this reply. I did share your issue with our product manager and he's been working on a fix with the developer team. We believe we've isolated the issue to the Gaming toolkit causing some incompatibilities with certain hardware drivers and configurations. We're still in the middle of working on it but I'll definitely update when there's news.
@Saiber77 - And, we always read and care... just somewhat short on resources and we just finished a week-long public holiday here.
Thanks!
Saiber77 said:
I have downloaded and run Remix OS Player on two different computers now and neither one of them has captured my hardware keyboard, I can use the onscreen keyboard but that really lessens the functionality and is half the point of having it run on a desktop. Can anyone advise as to how to resolve this issue? The options, advanced options, and the OS options are so dummy proofed it is impossible to do anything advanced. Is there config files I can edit or...?
Click to expand...
Click to collapse
I just installed Remix Player on my Intel NUC and find that my keyboard is not recognized at all. I have a Corsair K70 keyboard that besides being an incredible mechanical keyboard works otherwise great under Windows 10. Hopefully Jide can provide a solution.
Wow, public holidays, devs know what it is and have that too ?
Whatever. I run on a laptop, but if you need info about hardware I'll give. Thought it's already done in the hardware thread. Sorry not being able to remember exactly since what action from me the keyboard stopped being recognized (and I don't think I tried the gaming toolkit, if I'm right about it being the d pad we can see on the right).
Hello. New user here.
This might seem weird but I also had the trouble of not being able to type anything inside the player (was trying to login to the Play Store but couldn't type in my email address). I can use the CTRL+ALT keys to get the pointer out and I see the pinch? option when I hold down the CTRL key. But when I installed the terminal/command window app, the keyboard began working inside the player (weird right?)
http://forum.xda-developers.com/rem...s-player-update-1-0-107-t3477535#post69082434
Since update said "Fixed keyboard input issue when key-mapping is activated"
Just to notify. It's not solved : still no keyboard.
Windows 10
Microsoft K830 Keyboard
I just found this OS; but like others crtl+alt is working, but nothing else. Hope it can be resolved so I can use the keyboard to play games
how can i enable virtual keyboard?
yea the keyboard outside American is pretty bad,my French keyboard here is not supported very well,but the player is still in early beta stage so can't complain here.there are better emulator .
The dev team has been alerted to this thread and the issues being expressed here. I'll update when there are either fixes, or if there's something you guys could help us with to solve these keyboard issues.
As for holidays, our devs work at least through Saturdays and some work Sundays as well. However, for state appointed holidays, it's illegal to order staff to work, so it's entirely up to the staff.
Thanks again!
Esdeve said:
http://forum.xda-developers.com/rem...s-player-update-1-0-107-t3477535#post69082434
Since update said "Fixed keyboard input issue when key-mapping is activated"
Just to notify. It's not solved : still no keyboard.
Click to expand...
Click to collapse
i used to have the same problem, but i get to fix it making this:
- Open Remix Player
- Go to the last button on the white bar on the right side of the screen emulator (3-dot button)
- On the new pop-up screen, go to settings, and change the keyboard shortcuts option to Emulator Device ( default)
- Go and check if Remix Player can recognize Keyboard Input, if not, go back and change again the keyboard shortcuts option to Virtual Device and check if now Remix Player recognize Keyboard Input.
I hope that this steps can solve the problem for everyone.
psd: I don't know if it's needed to do this every time the emulator runs, if the keyboard is not working each time the emulator starts, then i assume that its have to be done this if you want to get to work your keyboard.
If you have the issue, can please try @starfoxcom 's solution?
We think this could be possibly fix the issue. We are trying to fix this issue fundamentally.
Bill
PM of Remix OS Player
starfoxcom said:
i used to have the same problem, but i get to fix it making this:
- Open Remix Player
- Go to the last button on the white bar on the right side of the screen emulator (3-dot button)
- On the new pop-up screen, go to settings, and change the keyboard shortcuts option to Emulator Device ( default)
- Go and check if Remix Player can recognize Keyboard Input, if not, go back and change again the keyboard shortcuts option to Virtual Device and check if now Remix Player recognize Keyboard Input.
I hope that this steps can solve the problem for everyone.
psd: I don't know if it's needed to do this every time the emulator runs, if the keyboard is not working each time the emulator starts, then i assume that its have to be done this if you want to get to work your keyboard.
Click to expand...
Click to collapse

hardware keyboard hooks

Hi
I have some experience in android development, now trying myself in xposed modules. Sorry if i missed the newbie thread - couldn't find it.
The question is - how to get all key events for hardware keyboard. Solution would be nice, but some pushes in right direction is fine too.
The idea is - make hotkey control for some application-specific actions (which isquite useful for android tv boxs).
P.S.
Sorry for my bad English, it's not my native language, and Russian is not remotely close to English.
iindeec said:
Hi, I have some experience in android development, now trying myself in xposed modules. Sorry if i missed the newbie thread - couldn't find it. . The question is - how to get all key events for hardware keyboard. Solution would be nice, but some pushes in right direction is fine too. The idea is - make hotkey control for some application-specific actions (which isquite useful for android tv boxs). P.S. Sorry for my bad English, it's not my native language, and Russian is not remotely close to English.
Click to expand...
Click to collapse
I've never developed a Module but, the following are 2 threads are very good guides as well as Q&A support.
https://forum.xda-developers.com/showthread.php?t=2709324
https://forum.xda-developers.com/showthread.php?t=2637006
Good Luck!
~~~~~~~~~~~~~~~
I DO NOT PROVIDE SUPPORT VIA PM UNLESS ASKED/REQUESTED BY MYSELF.
PLEASE KEEP IT IN THE THREADS WHERE EVERYONE CAN SHARE
Actually found a way to work with keyboard(or to be exact - all hardware keys). The key is AccessibilityService. Hope it'll be useful for someone.

Categories

Resources