Sign in to follow this  
Followers 0
Zwilk

Simulate POWER key

6 posts in this topic

#1 ·  Posted (edited)

Maybe I first have to mention I am a complete layman in programming. I have done HTML5 and CSS3, but I understand this is complete different.
 
A while ago I was asked to use a Teensy 2.0 as USB emulator. The intention was to shut Windows down with this emulator. My task was to write a code by using the following scan codes, found on www.win.tue.nl. 
 
              Set-1 make/brake     Set-2 make/brake
Power    e0 5e / e0 de            e0 37 / e0 f0 37
Sleep     e0 5f / e0 df              e0 3f / e0 f0 3f
Wake     e0 63 / e0 e3             e0 5e / e0 f0 5e 
 
So on the internet I found AutoIt when I searched for keystrokes. My question is: how can I use AutoIt to simulate the power key? Is there a possibility to use the above called information to shut down a Windows PC? 
 
I hope someone has a solution to help me.
 
Best regards,
Zwilk
Edited by Zwilk

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi Zwik,

welcome to the AutoIT forums :)

if you're looking to shutdown the pc, you could just use a hidden command prompt to achieve this:

run(@comspec & " /c shutdown /s /t 0","",@SW_HIDE)

the @COMSPEC is an AutoIT macro (it is the directory to cmd, so AutoIT runs command prompt)

the /c is a cmd parameter meaning execute this code

the rest is command line syntax for the shutdown command (/s is local, /t is the time in which to shutdown, 0 being immediately)

the second parameter of the  run function is the working directory for the program being run.

The third and final parameter used "@SW_HIDE" is the AutoIT macro for hiding a window, Meaning the cmd won't pop up on the screen.

Hopefully this helps you acheive what you're after?

I've attempted to go into detail, but if you need further explanation, Just let me know?

Many Thanks

Javi


EDIT: Just re-read your original request, If you're required to use those codes, then I'm afraid I don't know how to achieve this in AutoIT. Hopefully one of the more experienced coders on here can lend a hand :)

Edited by javiwhite

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites

@javiwhite, why would you suggest the OP go through all that rather than just using the native Shutdown() command in AutoIt?

@zwilk, not being familiar with Teensy, how are you presented with those codes (pop up display, output to log file, etc.)? That will determine how you capture them and then make your action decisions.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@javiwhite, why would you suggest the OP go through all that rather than just using the native Shutdown() command in AutoIt?

 

All that? It still equates to one line of code, and provides the user with greater customisation over the shutdown command. (Timeouts, Remote machines shutdowns etc...)

I wasn't aware of the native Shutdown() command, And after reading the syntax, I still wouldn't have suggested it for the aforementioned reasons...

But there's always more than one way to skin a cat I suppose. 


give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites
@javiwhite
 First, thank you for the fast reply. As you say, I have to use the above called scan codes. But if I want to use the @COMSPEC macro, can I copy this line 1:1 to the Arduino IDE? Because the Arduino uses C++...
 
@JLogan3o13
 Thanks for the reply! I haven't got these codes by myself so I do not know how these are presented. I found them on win.tue.nl. As far as I understand the keyboard generate these codes when pressed(make) a key and send them to the PC. When the button is released(brake), the keyboard sends a new scan code. 
 
Because there are keyboards available who have power/sleep/wake buttons I thought is would be simple. Just use one of the following lines and put a scan code in the parentheses. 
 Serial.println(number);       
  Serial.println(number, DEC);  
  Serial.println(number, HEX);  
  Serial.println(number, OCT);  
  Serial.println(number, BIN);  
  Serial.println(number, BYTE); 
  Serial.println(3.14);
  Keyboard.press(KEY);
  Keyboard.release(KEY);      
But unfortunately it is not that easy. Is it even possible because not all keyboards have these buttons?  
 
/Zwilk

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0