So i'm trying to simulate a key press in minecraft, but for some reason it doesn't work.
Every time i test outside, it writes exactly what i told it to write, but in minecraft, it doesn't do anything.
Does anyone know how to fix this ?
Related
Is there any way to look for console input under MicroPython without pausing the program?
Within a program, I can use, for example, uart1.any() to see if there is anything in the input buffer. If not, the program can just continue.
I have a system that runs autonomously. However, I want to be able to modify parameters after the program has started using the console. The problem is, if I just use input() then the program will pause, even if I don't want to take any action.
What I need is to be able to check the "console input buffer" periodically to see if I have entered anything and, if so, process that input, otherwise to just continue.
Is this possible?
=====================================
Many thanks for the suggestion! It works, but...
What I am trying to do is to run a process which can be interrupted by keyboard input and diverted to another process. When that is finished, I return to the original process.
The initial part works well; I poll stdin and nothing happens until I hit return (for example). The program then correctly diverts to the other routine. However, when that is finished, and I return to the original thread, it immediately diverts again, even though I have not pressed any further keys.
I have tried setting 'keypress' to None after trapping it; I have tried using stdin.flush - which doesn't work! It's as though there is still something in the input buffer that I need to purge.
Any ideas?
You can poll stdin to see if data is available before attempting to read it.
from sys import stdin
from select import poll, POLLIN
poll_obj = poll()
poll_obj.register(stdin, POLLIN)
keypress = stdin.read(1) if poll_obj.poll(0) else None
print(keypress)
I need to configure daily dozens of devices through serial port. The config is at it follows:
Wait for boot (i.e. a specific line appears).
Enter a sequence of commands.
Do a 'print' to check everything is right.
Move to next device.
It doesn't seem complicated, and I really need to automate it. I'm not an expert programmer, but I find my ways.
What can you suggest me to get started? Where should I look on? In particular, any great API out there that would do the dirty job for me? I'm using Windows, but I could get Linux too if really needed.
The one language that I've studied is C. But I'm open to something new as long as it can be done fast.
Thank you in advance.
That looks like a task for expect:
#!/usr/bin/expect
set timeout 20
spawn "terminal-program"
expect "a specific line"
send "sequence_of_commands"
expect "prompt >"
send "print"
and put that in a bash-loop.
I am working on the CAN on LPC1857 microcontroller. This is the first time I am working on the CAN driver.
I am right now testing the loopback mode in CAN. I have successfully transmitted the message. This I know because of the values in the status register. But now I need to verify whether I have received the same message at the receiver end. Since I do not have any oscilloscope with me, I wanted to know whether it is possible to check the output at the receiver end using software. I am using LPCxpresso IDE for the coding purpose. If yes, can you please give me a brief idea about how it is done?
Any help is appreciated.
Thanks,
Pavan.
I'm not even sure whether I've framed this question correctly. Let me explain my situation.
I have an Application hosted in a OpenVMS environment which is being accessed via Telnet. I'm in need to programmatically accomplish certain tasks.
So far I could send and receive messages using a C# Telnet Client. I am able to execute tasks by sending commands and receiving responses. But for one task, I have to edit a Form to change some information. The command looks like below
>modify page <page_no>
As soon as I enter the above command, the entire terminal gets loaded with this Form, I have to use page-down to go through the fields, press enter to edit the text and use Ctrl-Z to save it.
I'm not sure how to accomplish this task programmatically.
I'm not familiar with telnet or VxWorks. I'm not sure the above is a feature of Telnet or OpenVMS. Kindly help.
This should be easy to figure out thanks to the clear text of telnet :D It shouldn't matter what platform your target is running. All you have to remember is that special keys like ctrl-z or page down, are just chars in the data stream. Ctrl-z is typically 0x1a, and I am not sure what page down is off the top of my head, but here is how you can figure it out:
Get wireshark http://www.wireshark.org/ and install it if you don't already have it.
Start wireshark up and capture all traffic on your NIC that will carry the connection to the target.
Start a normal telnet session to the target and issue all of the commands (including the page downs and the ctrl-z).
Stop wireshark capture and then filter out everything except telnet communication between you and the target.
Look at the data that was sent to issue the ctrl-z, and page downs.
Put those chars in your telnet stream when you are ready to issue those commands.
Easy.
I am writing an app with a synchronization feature. And whenever the app finds a conflict between two objects, i want to display something for the user to choose the correct value.
My first idea was to use UIAlertView but after i create the alert object and show it, the program continues the execution, and may eventually find other conflicts before the user had time to resolve the first one.
My question here is: is there a better approach on this ? Or is there a way to stop the app and wait for the alert's choice ?
Any links, further reading or suggestions are much appreciated. Thanks for your help and time
It depends on how you're setting it up. What you should do is terminate execution of the synchronization when a conflict is found, then start it again from the method called by the alertview.