Method To Detect On-Screen Keyboard is Active?

1,778 views
Skip to first unread message

Paul [sabret00the]

unread,
Aug 18, 2013, 2:26:36 PM8/18/13
to tas...@googlegroups.com
I had a dummy task that I'm sure was working with the _keyboard out_ state, but upon reading up on why it's not working now, I'm not so sure as it's apparently only for physical keyboards. Does anyone know of a method for software keyboards?

Matt R

unread,
Aug 18, 2013, 4:22:35 PM8/18/13
to tas...@googlegroups.com
The only way I can think of would be to look in the dumpsys log. On my phone, running the shell script:

dumpsys input_method | grep InputShown

returns a line that contains mInputShown=true (or false). This requires root.

Matt

Brandon Horwath

unread,
Aug 18, 2013, 5:25:25 PM8/18/13
to tas...@googlegroups.com
I have been vigilantly searching for a method to detect soft keyboard appearance on screen and/or key presses without root.

Nothing so far... sorry.

TomL

unread,
Aug 19, 2013, 12:50:50 PM8/19/13
to tas...@googlegroups.com
I bet you can detect it without root using the same tricks as bckground processs detection. you would need to do the following

ps
to get the list of current processes
find the keyboard process
check the oom_adj value for that process
to determine if keyboard being shown.

Tom

Mike L

unread,
Aug 19, 2013, 2:36:57 PM8/19/13
to tas...@googlegroups.com
This is on my phone so I couldn't tell you if this is for all.
When my keyboard is open, it throws a notification. It only starting doing this after I installed another keyboard (hackers keyboard) though. So %NTITLE could prove useful if this is the case on your phone

Brandon Horwath

unread,
Aug 19, 2013, 5:40:11 PM8/19/13
to tas...@googlegroups.com
When my keyboard appears a notification with title, "Select Input Method" appears.

But... tasker CANNOT detect it appearing or being displayed at all!

Paul [sabret00the]

unread,
Aug 19, 2013, 5:41:55 PM8/19/13
to tas...@googlegroups.com

Oh, so it's not just me then.

On 19 Aug 2013 22:40, "Brandon Horwath" <brandon...@gmail.com> wrote:
When my keyboard appears a notification with title, "Select Input Method" appears.

But... tasker CANNOT detect it appearing or being displayed at all!

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/k3kK7onhBtg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.

Pent

unread,
Aug 20, 2013, 2:32:35 AM8/20/13
to tas...@googlegroups.com
Android doesn't provide any way to detect this.

Even for the foreground app, you can only detect it indirectly by looking at the size of layouts.

Unless they added an API I missed recently.

Pent

Paul [sabret00the]

unread,
Aug 22, 2013, 3:10:38 AM8/22/13
to tas...@googlegroups.com

By why chance, would you happen to know how to check the size of the layouts?

--

Bob Hansen

unread,
Aug 22, 2013, 9:41:37 AM8/22/13
to tas...@googlegroups.com
I have to agree with TomL, that the softkey board can be detected without root, by using the oom_adj value of the keyboard app. When the keyboard is visible, the oom_adj value will be 1 and when it is not visible it will be 2 or greater. 

Getting an apps oom_adj value requires a single command run in a Tasker Run Shell action. For SwiftKey, the command looks like this:

     cat /proc/$(pgrep com.touchtype.swiftkey)/oom_adj

For any other app, the only change needed is to replace the swiftkey package name with the desired app's package name. A running app's package name can easily be found by going into the device's settings and selecting Apps then selecting the Running column (tab) and selecting the desired app from the list. Look at the Processes section and you will see the package name on the line below the app's name.

Here is a Tasker profile description for a proof of concept. When you shake your device it will flash the status of the SwiftKey keyboard app. Here is the profile that can be imported into Tasker: http://db.tt/CzmxYzGL

Profile: SwiftKey Status (148)
Event: Shake [ Axis:Left-Right Sensitivity:Medium Duration:Medium ]
Enter: SwiftKey Check (149)
A1: Run Shell [ Command:cat /proc/$(pgrep com.touchtype.swiftkey)/oom_adj Timeout (Seconds):0 Use Root:Off Store Output In:%oom_adj Store Errors In:%err Store Result In: Continue Task After Error:On ] 
A2: If [ %err Is Set ]
A3: Flash [ Text:SwiftKey not running Long:On ] 
A4: Else If [ %oom_adj < 2 ]
A5: Flash [ Text:SwiftKey
%oom_adj Running in foreground Long:On ] 
A6: Else If [ %oom_adj > 1 ]
A7: Flash [ Text:SwiftKey
%oom_adj Running in background Long:On ] 
A8: End If 

Brandon Horwath

unread,
Aug 24, 2013, 2:48:27 PM8/24/13
to tas...@googlegroups.com
I get this error:

sh: <stdin>[2]: pgrep: not found
sh: <stdin>[2]: cat: /proc//oom_adj: No such file or directory

I will admit I know very little about shell scripts command syntax, but can someone point out what is the user error here?

TomL

unread,
Aug 24, 2013, 5:20:37 PM8/24/13
to tas...@googlegroups.com
Brandon, it looks like you don't have Busybox installed. Stock android doesn't have shell commands like pgrep or pidof or grep. This technique is possible using stock Android, just a few more steps.

Look in this thread
https://groups.google.com/d/msg/tasker/HqBGTsmwvsw/KhCRR2dPVt0J

It's a long thread, but I walked some users thru how to get oom_adj on stock android without root.

Brandon Horwath

unread,
Aug 24, 2013, 6:13:32 PM8/24/13
to tas...@googlegroups.com
I have been using the action assistant plugin to determine this value. But, the plugin doesn't initiate until the end of a task regardless of action placement within task, which makes it difficult to work with.

Thanks for the info, I will look into that. It just sounded easier to do than I thought I guess.

Brandon Horwath

unread,
Aug 24, 2013, 9:47:58 PM8/24/13
to tas...@googlegroups.com
Actually... this works:

Profile: Adjust for STT (326)
Priority: 9 CoolDown: 0
State: Proximity Sensor
State: Variable Value [ Name:%PACTIVE Op:Matches Regex Value:Caller Recording Disable ]
Enter: HTC SENSE Input (336)
A1: Variable Clear [ Name:%OOMADJ Pattern Matching:Off ]
<HTC SENSE INPUT oomadj value>
A2: Action Box [ Configuration:[Get oom_adj]
com.htc.android.htcime, %OOMADJ Package:pe.lastingchild.actionbox Name:Action Box ]

Exit: Bluetooth Adjustment (335)
A1: If [ %OOMADJ < 2 ]
A2: Bluetooth Auto Connect [ Configuration:Data Package:org.myklos.btautoconnect Name:Bluetooth Auto Connect Continue Task After Error:Off ] If [ %OOMADJ < 2 ]
A3: Flash [ Text:Bluetooth Altered Long:Off ] If [ %OOMADJ < 2 ]
A4: Else
A5: Flash [ Text:Not Running Long:Off ]
A6: End If

This cuts my M2DP connection (if not in use) with Bluetooth when using Google speech to text recognition on the keyboard with a wave of my hand over the proximity sensor. Allowing me to use my headset when connected for quick text input. M2DP profile reconnects when headset media button is pressed, or simply resumes if already in use.

One issue resolved.

+1

Pent

unread,
Aug 25, 2013, 3:41:01 AM8/25/13
to tas...@googlegroups.com
>By why chance, would you happen to know how to check the size of the layouts?

Those are private to the foreground app.

It's conceivable it could somehow be detected via an accessibility service looking at
layouts, but I don't want to spend a while testing that theory right now.

Pent

Yash Srivastav

unread,
Oct 29, 2014, 1:40:49 AM10/29/14
to tas...@googlegroups.com
I know that this is an old thread but what I read here helped me to setup a system which would display a tint over the Keyboard whenever Keyboard is visible..I noticed that the only notification we receive from Android System is for changing keyboards.I used Matt's 

method of looking in the dumpsys log but since it's not always possible to keep running the shell script in the background,I use notification listener to check if there is a notification from android system and then run the following actions

1.Create Scene : Tint

2.Show Scene : Tint

3. Run Shell :  
     dumpsys input_method | grep InputShown
     Store output in : %result

4.if %result ~ *true* , goto 3

5.Hide Scene : Tint

6.Destroy Scene : Tint

Thus,the tint remains visible over the keyboard while it is visible and then it is destroyed

Thanks Guys,
Yash

Niccolò Coli

unread,
Feb 1, 2015, 3:18:34 PM2/1/15
to tas...@googlegroups.com
I do have busybox installed but I still get this error????

Stupifier

unread,
Feb 18, 2015, 11:43:46 AM2/18/15
to tas...@googlegroups.com
This worked nicely for me. Pretty much Copy/Pasted exactly what Bob Hansen said (except I checked "root" just because I'm rooted and it couldn't hurt. Good stuff.

whitedavidp

unread,
Apr 4, 2016, 4:55:16 PM4/4/16
to Tasker

i am using notification listener to see the Choose input method notification shown when the soft keyboard is active. on my phone this comes from the android system app. i can know which keyboard is currently selected since that is shown in the notification and made available by this excellent plug in. for some reason the built in tasker notification profile cannot seem to see this one.
Reply all
Reply to author
Forward
0 new messages