Simulate keypress in bash

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Simulate keypress in bash
# 1  
Old 06-25-2018
Simulate keypress in bash

Hello everybody,

I am using Windows 10 and cygwin/bash.

I need to write a script in bash which simulates opening of a program and then press some keys such as F5, ENTER and ALT+F4.

I have written a VBScript which does the job

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "Program"
WshShell.SendKeys "{F5}"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 8000
WshShell.AppActivate "Program"
WshShell.SendKeys "%{F4}"

but I need to use bash because the file I need to open is on the network.

I have no clue how to that with bash, any help is appreciated.

Thanks. Supernono06
# 2  
Old 06-25-2018
Help me out - why shouldn't windows be able to open a file on the network?
# 3  
Old 06-25-2018
BASH is poorly suited to this, almost nothing in Windows is designed using the UNIX process model. Your bash script will be a thin wrapper around whatever external utility you find which allows you to generate arbitrary keypresses (and odds are, that utility will be flagged and deleted by your antivirus).

Why not vbscript if you're really on win10?
# 4  
Old 06-26-2018
I have a batch file calling the vbscript, and when it is on shared directory I got
"CMD does not support UNC paths as current directories"
# 5  
Old 06-26-2018
MS Windows has three kinds of directory paths which partly overlap and partly don't and almost no programs implement all of them.

BASH would be no help here, as in UNIX, there's only one kind of path and network filesystems are the responsibility of the operating system, not the shell.

MS fortunately made a few kludges to join different kinds of paths together when your app needs a specific kind.

You should be able to turn a shared folder into a drive letter CMD can use, via something like
Code:
net use Z: \\computer_name\share_name /PERSISTENT:YES

That might even be a permanent mapping, unless you do
Code:
net use Z: /delete

These 5 Users Gave Thanks to Corona688 For This Post:
# 6  
Old 06-27-2018
Thank you Corona688, I will try this. I also had in mind to use pushd/popd, probably net use does the same?
# 7  
Old 06-28-2018
pushd/popd is just a wrapper made around cd, it doesn't possess the magical ability to convert a network path into a local one. Altering the universe like that is an operating system feature. You have to ask Windows to do what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash loop hording keypress input

I have a bash loop that waits for a single key press, then does $something depending on what $key is pressed before refreshing the screen with updated data. The problem I have is that the script will store additional key presses and chain them together causing the screen to redraw and the script... (1 Reply)
Discussion started by: DarkPhoenix
1 Replies

2. Programming

Simulate keypress inside a non-x application...

Hey guys, I'm looking for a solution to simulate a key-combo (tab+q) inside an amiga-emulator. I've tried it with uinput and python without any success. Any help would be great. Cheers McCarthy (5 Replies)
Discussion started by: mccarthy83
5 Replies

3. Shell Programming and Scripting

How to simulate ''Esc'' keystroke in a bash shel script?

I am using Ubuntu 12.4 I am running the following script: ++++++++ #!/bin/bash while ; do xdotool mousemove 248 539 click 1 & sleep 3 done +++++++++ This moves the mouse on the specified position on the screen and clicks that pauses the script for 3 seconds and repeats the... (2 Replies)
Discussion started by: alfarnume
2 Replies

4. Shell Programming and Scripting

How to simulate an execution queue with bash?

I'm running cygwin bash on windows 7 and I'm have some bat files that perform large builds and take a long time and a lot of memory. Therefor, I don't want to builds executing simultaneously (too much memory). How can I implement a queue so I can queue up multiple builds and only execute one... (2 Replies)
Discussion started by: siegfried
2 Replies

5. Programming

Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX

Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
Discussion started by: vrghost
7 Replies

6. Programming

get keypress c++Qt

Hi i need to get the key pressed from the keyboard without focus on the application. i work under CentOS 5.5 with QtC++ 4.7 and Python Script (0 Replies)
Discussion started by: HanyM.Magdy
0 Replies

7. Shell Programming and Scripting

Bash KeyPress (or Read Single Character)

Hi, I'm sorry if this has already been posted somewhere but I can't seem to find it on the forums (or anywhere on google :( ) I am writing a script where a user must enter a single character to perform an action. For example, Press Q to Quit or R to Refresh Basically I am stuggling... (5 Replies)
Discussion started by: Ste_Moore01
5 Replies

8. Shell Programming and Scripting

simulate session.getMaxInactiveInterval() in bash script

hi everyone, I have a question about the java object oriented function which to simulate in bash script... here is the function "session.getMaxInactiveInterval() / 60 " got any web can read this function? coz i need to simulate to bash script... Hope someone give me a suggestion... (0 Replies)
Discussion started by: ryanW
0 Replies

9. Shell Programming and Scripting

How to trap a user keypress

Yo, I program Unix for fun- except when editing my website removed by reborg - and wanted to learn how to track, trap, and use to my advantage a user keypress. I know there is a built-in JS function that can do that, but Javascript is a client-side language, therefore not usable in Unix, and... (2 Replies)
Discussion started by: signebedi
2 Replies

10. Programming

keypress signals

How-to use keypress action signals in C? Is there any nice select or poll functions for that? (1 Reply)
Discussion started by: Esaia
1 Replies
Login or Register to Ask a Question