0

I am having trouble with my digitizer and pen. The palmrejection detects the pen only when it's like 1cm above the screen.

So I'm trying to make a batch which disables or enables the touchscreen when executed.

devcon disable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

devcon enable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

Currently i have 2 seperate batches with one of the above commands and they work fine. But I want it in 1 file with an IF ELSE clause.

D:
cd D:\Windows Kits\10\Tools\x64
SET /P Test=devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
IF %Test% EQU 1(
devcon disable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
)ELSE(
devcon enable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
)

I tried, but I don't know how to use the status return as IF condition to en- or disable the touchscreen.

C:\WINDOWS\system32>D:

D:\>cd D:\Windows Kits\10\Tools\x64

D:\Windows Kits\10\Tools\x64>SET /P Test=devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

>>devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

This is returned by cmd when executed. The last line isn't executed, I can still edit it and press enter, then cmd closes.

D:\Windows Kits\10\Tools\x64>devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
HID\ELAN0732&COL01\5&242C8B19&1&0000
    Name: HID-konformer Touchscreen
    Device is disabled.
1 matching device(s) found.

status if device is disabled

D:\Windows Kits\10\Tools\x64>devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
HID\ELAN0732&COL01\5&242C8B19&1&0000
    Name: HID-konformer Touchscreen
    Driver is running.
1 matching device(s) found.

status if device is enabled

Kiljab
  • 3
  • 2

1 Answers1

0

To get the output of a command into a variable, use a for /f loop. Filter the line you need (Device is xxxxx) and get the third token (word) from this line:

for /f "tokens=3" %%a in ('devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"^|find "Device is"') do set "status=%%a"
echo status is %status%

The rest of your code is not quite correct (batch is a bit picky with spaces) and I changed the if to string comparison to make it safe against an empty %status% variable:

IF "%status%" == "running" (
  devcon disable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
) ELSE (
  devcon enable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
)
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Thanks very much! I tested it, but it always disables the screen :D The output of cmd during this script is `D:\Windows Kits\10\Tools\x64>set "status=HID\ELAN0732&COL01\5&242C8B19&1&0000" D:\Windows Kits\10\Tools\x64>set "status=Name:" D:\Windows Kits\10\Tools\x64>set "status=Driver" D:\Windows Kits\10\Tools\x64>set "status=1" status is 1` It always gets status 1, no matter if enabled or disabled. I try to figure out how to take another part of the status return to use for comparison. – Kiljab Nov 10 '20 at 09:23
  • the `1` you get is the first token of the last line ("**1** matching device(s) found."). I changed the code according to the provided output of `devcon`. I don't use `devcon`, so I hope it works. – Stephan Nov 10 '20 at 10:08
  • Thanks! It fristly didn't work correct, but I saw that the output is "Driver is..." or "Device is...", so I just changed the IF clause to `IF "%status%" == ""`. I could also have switched the operations and changed the IF clause to `IF "%status%" == "disabled"`, but it works now like it should :-) – Kiljab Nov 10 '20 at 11:06
  • oh - I didn't notice the output is different ("driver" vs. "device"). Which reminds me of a simpler solution: `devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000" |find "running" >nul && set "status=running" || set "status=disabled"` – Stephan Nov 10 '20 at 11:16