I want to make AutoIt display a msgbox when system is about to shutdown or reboot.
I tried this one:
#include <WindowsConstants.au3>
$hGUI = GuiCreate("") ; Create a GUI and don't show it
GuiRegisterMsg($WM_ENDSESSION, "WM_ENDSESSION")
; Do stuff here...
While 1 ; Loop does nothing
Sleep(100)
WEnd
Func WM_ENDSESSION($hWnd, $Msg, $wParam, $lParam)
MsgBox(0,"SystemShutdown", #HOUR & ":" & #MIN & ":" & #SEC & #TAB & "WM_ENDSESSION: " & $hWnd & ", " & $Msg & ", " & $wParam & ", " & $lParam & #CRLF)
EndFunc
But it won't work?
Try this :
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <date.au3>
;~ #define PBT_APMQUERYSUSPEND 0x0000
;~ #define PBT_APMQUERYSTANDBY 0x0001
;~ #define PBT_APMQUERYSUSPENDFAILED 0x0002
;~ #define PBT_APMQUERYSTANDBYFAILED 0x0003
;~ #define PBT_APMSUSPEND 0x0004
;~ #define PBT_APMSTANDBY 0x0005
;~ #define PBT_APMRESUMECRITICAL 0x0006
;~ #define PBT_APMRESUMESUSPEND 0x0007
;~ #define PBT_APMRESUMESTANDBY 0x0008
;~ #define PBTF_APMRESUMEFROMFAILURE 0x00000001
;~ #define PBT_APMBATTERYLOW 0x0009
;~ #define PBT_APMPOWERSTATUSCHANGE 0x000A
;~ #define PBT_APMOEMEVENT 0x000B
;~ #define PBT_APMRESUMEAUTOMATIC 0x0012
Global $PBT_APMSUSPEND = 0x0004
Global $PBT_APMRESUMESUSPEND = 0x0007
Global $PBT_APMSTANDBY = 0x0005
Global $PBT_APMRESUMESTANDBY = 0x0008
$hGUI = GUICreate("Test", 100, 100, 1, 1)
GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
GUIRegisterMsg($WM_QUERYENDSESSION, "_Shutdown")
;~ GUISetState()
While 1
Sleep(10)
;~ $GUIMsg = GUIGetMsg()
;~ Switch $GUIMsg
;~ Case $GUI_EVENT_CLOSE
;~ ExitLoop
;~ EndSwitch
WEnd
;
Exit
;
Func Standby($hWnd, $Msg, $wParam, $lParam)
ConsoleWrite(_NowTime() & ": " & $wParam & #LF)
Select
Case $wParam = $PBT_APMSUSPEND
ConsoleWrite(" You going into Suspend." & #LF)
Case $wParam = $PBT_APMRESUMESUSPEND
ConsoleWrite(" You just woke up from Suspend." & #LF)
Case $wParam = $PBT_APMRESUMESTANDBY
ConsoleWrite(" You are going into Standby." & #LF)
Case $wParam = $PBT_APMRESUMESTANDBY
ConsoleWrite(" You just woke up from Standby." & #LF)
;MsgBox(0,"Hello Back", " You just woke up from Standby")
Case Else
EndSelect
EndFunc ;==>Standby
Func _Shutdown()
MsgBox(16, 'SHUTDOWN', ' oh oh shutting down ... ')
EndFunc ;==>_Shutdown
Related
I'm trying to convert the numerical result into words.
The sample I found works well for English words, but as I change them to my language, bunch of superficial problems came out.
What I need help in particular with is building the same code for 100 as its for 10. The reason I am doing this is because in my language we don't have One standing in front of every Hundred/Thousand
For example: Let's say the first number in Ones is called Taff
As it is, the program will make Taff Hundred where it should make make something like Taffss Hundred
So I created the Hundreds() which includes the correct callings.
Ones() contains the words from 1 - 9
Teens() contains the words from
11 - 19
Tens() contains the words from 10 - 90 (10,20,30 etc)
Hundreds() contains the words from 100-900 (100,200,300 etc)
Here is my code :
intAmount = eAmount
Dim nTousands As Integer = intAmount \ 1000 : intAmount = intAmount Mod 1000
Dim nHundred As Integer = intAmount \ 100 : intAmount = intAmount Mod 100
Dim nTen As Integer = intAmount \ 10 : intAmount = intAmount Mod 10
Dim nOne As Integer = intAmount \ 1
If nTen > 0 Then
If nTen = 1 And nOne > 0 Then
wAmount = wAmount & Teens(nOne) & " "
Else
wAmount = wAmount & Tens(nTen) & IIf(nOne > 0, " и ", " ")
If nOne > 0 Then wAmount = wAmount & Ones(nOne) & " "
End If
End If
ElseIf nOne > 0 Then
wAmount = wAmount & Ones(nOne) & " "
wAmount = wAmount & HMBT(nSet) & " "
wAmount = AmountInWords(CStr(CLng(nAmount) - _
(eAmount * multiplier)).Trim & tempDecValue, wAmount, nSet - 1)
Being the noob I am, I figured that by copy pasting the code for 10s, and changing the values to 100s will make things work, but it only works for 100 200 300 etc, not for the numbers in-between.
ElseIf nHundred > 0 Then
If nHundred = 1 And nOne > 0 Then
'Don't know how to properly add things here.
Else
wAmount = wAmount & Hundreds(nHundred) & IIf(nOne > 0, " и ", " ")
If nOne > 0 Then wAmount = wAmount & Ones(nOne) & " "
End If
Update
I made some changes, this time it partially works...
It shows 100s, 200s, 300s etc etc.
But it only shows from 100 to 109 when it "increments" If it goes above 109, the 100s aren't show, and it goes back to showing 10s, 11s, 12s etc.
ElseIf nHundred > 0 Then
If nHundred = 1 And nTen > 0 And nOne > 0 Then
wAmount = wAmount & Teens(nTen) & " "
Else
wAmount = wAmount & Hundreds(nHundred) & IIf(nOne > 0, " и ", " ")
If nOne > 0 Then wAmount = wAmount & Ones(nOne) & " "
End If
Made some changes... Is this closer to what you're after?
Private list_ones() As String = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}
Private list_teens() As String = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}
Private list_tens() As String = {"ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"}
Private list_hundreds() As String = {"ones", "two", "three", "four", "five", "six", "seven", "eight", "nine"}
Private Function get_string_from_numeric(ByVal curr_number As Integer) As String
Dim to_return As String = ""
Try
Select Case curr_number
Case Is < 10
to_return = list_ones(curr_number)
Case 10 To 19
to_return = list_teens(curr_number - 10)
Case 20 To 99
to_return = get_return_value(curr_number, 10, list_tens)
Case 100 To 999
to_return = get_return_value(curr_number, 100, list_hundreds, "hundred")
Case 1000 To 9999
to_return = get_return_value(curr_number, 1000, list_hundreds, "thousand")
Case Is > 9999
to_return = "out of range"
End Select
Catch
Finally
End Try
Return to_return
End Function
Private Function get_return_value(ByVal curr_number As Integer, ByVal curr_pace_holder As Integer, ByVal curr_array_list As String(), Optional ByVal str_term As String = "") As String
Dim to_return As String = ""
Dim curr_iter As Integer = Math.Floor(curr_number / curr_pace_holder)
Dim curr_remainder As Integer = curr_number - curr_iter * curr_pace_holder
If (str_term <> "") Then str_term = " " & str_term
If (curr_remainder > 0) Then
to_return = curr_array_list(curr_iter - 1) & str_term & " " & get_string_from_numeric(curr_remainder)
Else
to_return = curr_array_list(curr_iter - 1) & str_term
End If
Return to_return
End Function
Private Sub cmd_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_submit.Click
Try
If (IsNumeric(txt_input.Text)) Then
txt_output.Text = get_string_from_numeric(CInt(txt_input.Text))
Else
MsgBox("Invalid input.")
End If
Catch
Finally
End Try
End Sub
I would like to solve the following testing problem. If there is an error i.e. (=1/0) in a cell, the additional tests will not run after that. I would like to know how to solve this issue in the testing primary task part.
Private Sub ts_NoBlank(TsCn, STST, LsSt, LsIn, TsRw, MsCo, MsIC, MsSt)
Dim TsCl, StRw, LsRw, TsSh
TsCl = ColNrOfField(TsCn)
StRw = FsRwOfField(TsCn) + 1
LsRw = LsRwOfField(TsCn)
TsSh = SheetOfField(TsCn)
' Setting up Status Updates
PLcSt = -1 'Starting previous local status is set to -100% to show eitherways
rws = LsRw - StRw
'this part has to be copied to whenever showing the status (Value of LcSt has to be added each time by function)
LcSt = 0
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
' Testing primary task
ErrNr = 0
For Rw = StRw To LsRw 'ToDo speed up with fromrow torow
If Len(ThisWorkbook.Sheets(TsSh).Cells(Rw, TsCl)) = 0 Then
ThisWorkbook.Sheets(TsSh).Cells(Rw, TsCl).Interior.ColorIndex = 46
ErrNr = ErrNr + 1
End If
'Showing Local Status
LcSt = 0.1 + ((Rw / LsRw) * 0.75)
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
Next Rw
' Updating Test Results on 'Testing' Page
TRRg = "test" & TsRw & "_results"
If ErrNr = 0 Then 'If Results are Positive
ThisWorkbook.Worksheets("Testing").Range(TRRg) = MsCo
ThisWorkbook.Worksheets("Testing").Range(TRRg).Interior.ColorIndex = 51
Else 'If Errors are found
ErrMS = NumberizeMessage(MsIC, "SP_textvers", "S_textvers", "P_textvers", ErrNr)
ThisWorkbook.Worksheets("Testing").Range(TRRg) = ErrMS
ThisWorkbook.Worksheets("Testing").Range(TRRg).Interior.ColorIndex = 3
End If
'Showing Local Status
LcSt = 0.1
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
' Highlighting erroneous cells (if not done during testing)
If ErrNr > 0 Then
End If
'Showing Local Status 100%
LcSt = 1
If LcSt - PLcSt >= LsIn Then
Call ShowStatus(MsSt & " (" & Application.WorksheetFunction.Text(LcSt, "0%") & ")", ThisWorkbook.Worksheets("Calculations Running").Range("Started"), STST + (LsSt - STST) * LcSt)
PLcSt = LcSt
End If
End Sub
Since you indicate that the ' Testing primary task section seems to work, but nothing after that seems to execute, I'd suggest that when you get here:
'Showing Local Status
LcSt = 0.1
If LcSt - PLcSt >= LsIn Then
this condition is false, so the code is never executed.
Then you get here:
' Highlighting erroneous cells (if not done during testing)
If ErrNr > 0 Then
End If
and there is no code to execute, no matter the value of ErrNr.
Then you get here:
'Showing Local Status 100%
LcSt = 1
If LcSt - PLcSt >= LsIn Then
and it's still evaluating False, so again it never executes.
Have you gone through in the debugger to look at the values and ensure everything is as you expect it to be?
Ok, so I'm creating an AutoIt GUI executable to automate some functions in a website. However, I cannot find a way to break the While loop that executes the function I've created using a "STOP" button I've created. Therefore, it runs indefinitely, and I cannot quit the program. In theory, it should work, but I feel I'm missing something. Any help, folks?
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Global $msg, $instructions, $AutoLevel, $NumDogsBox, $NumDogs, $IE, $i, $o
$IE = _IECreateEmbedded()
GUICreate("Automatic Dog Feeder for Criminal Case", 900, 690)
$instructions = GUICtrlCreateButton(' Instructions ', 725, 5)
GUICtrlCreateLabel("# of Dogs: ",740,40)
$NumDogsBox = GUICtrlCreateInput("", 815, 37, 25)
$AutoLevel = GUICtrlCreateButton(' Begin Auto Feed Dog ', 700, 65)
GUICtrlCreateObj($IE, 1, 100, 915, 610)
GUISetState(#SW_SHOW)
_IENavigate($IE, "http://apps.facebook.com/criminalcase")
$IE.Document.Body.Scroll = "no"
_IEAction($IE, "stop")
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $instructions
MsgBox(0,"Instructions","1.) Log in to Facebook (if not already) in the window below" & #CRLF & "2.) Clear any notifications and get to the map screen" & #CRLF & "3.) Click on the dog bowl icon on the right of the map" & #CRLF & "4.) Enter the number of dogs you have to level up" & #CRLF & "5.) Click the Begin Auto Feed Dog button at the bottom of the window")
Case $msg = $AutoLevel
$NumDogs = GUICtrlRead($NumDogsBox)
AutoDogLevel()
EndSelect
WEnd
Func AutoDogLevel()
While 1
$stop = GUICtrlCreateButton('STOP',830,65)
$i=0
While $i < $NumDogs
If $msg = $stop Then
ExitLoop
Endif
MsgBox(0,"","1xp" & $i+1)
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]","","","left",1,156,651)
Sleep(2000)
If $msg = $stop Then
ExitLoop
Endif
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]","","","left",1,723,524)
MsgBox(0,"","Next Dog")
Sleep(2000)
$i = $i+1
WEnd
If $msg = $stop Then
ExitLoop
Endif
While $i > 0
If $msg = $stop Then
ExitLoop
Endif
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]","","","left",1,62,525)
MsgBox(0,"","Previous Dog")
If $msg = $stop Then
ExitLoop
Endif
Sleep(1000)
$i=$i-1
WEnd
If $msg = $stop Then
ExitLoop
Endif
Sleep(3000)
WEnd
EndFunc
So, now I'm stuck. Any help will be greatly appreciated.
It's not a good idea to have more than 1 message loop for a GUI. Instead of doing it like this, I suggest keeping a variable for the current state, and only implementing a single loop. You also have some very large sleeps inside the message loop as well.
I haven't tested the code, but here is the message loop re-written to use a state variable and timers instead of multiple loops and sleeps. This is a much better design that will ensure your GUI is always responsive to ALL the buttons, and I think you'll find it easier to work with as well once you get used to the structure.
Local $iState = 0, $i, $iTimer
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $instructions
MsgBox(0, "Instructions", "1.) Log in to Facebook (if not already) in the window below" & #CRLF & "2.) Clear any notifications and get to the map screen" & #CRLF & "3.) Click on the dog bowl icon on the right of the map" & #CRLF & "4.) Enter the number of dogs you have to level up" & #CRLF & "5.) Click the Begin Auto Feed Dog button at the bottom of the window")
Case $msg = $AutoLevel
$NumDogs = GUICtrlRead($NumDogsBox)
$stop = GUICtrlCreateButton('STOP', 830, 65)
$iState = 1
$i = 0
Case Else
If $iState = 1 Then
If $i >= $NumDogs Then
$iState = 3
ContinueLoop
EndIf
MsgBox(0, "", "1xp" & $i + 1)
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]", "", "", "left", 1, 156, 651)
$iState = 2
$iTimer = TimerInit()
ElseIf $iState = 2 Then
If TimerDiff($iTimer) < 2000 Then ContinueLoop
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]", "", "", "left", 1, 723, 524)
MsgBox(0, "", "Next Dog")
$iTimer = TimerInit()
$i = $i + 1
ElseIf $iState = 3 Then
If TimerDiff($iTimer) < 1000 Then ContinueLoop
If $i <= 0 Then
$iState = 1
ContinueLoop
EndIf
ControlClick("[CLASS:MacromediaFlashPlayerActiveX]", "", "", "left", 1, 62, 525)
MsgBox(0, "", "Previous Dog")
$iTimer = TimerInit()
$i = $i - 1
EndIf
EndSelect
WEnd
here is the following code which works just fine:
sCharacterUid = "394F73";
size_t pos;
sPos1 = sCharacterUid.substr(4,1);
sPos2 = sCharacterUid.substr(5,1);
sPos3 = sCharacterUid.substr(2,1);
sPos4 = sCharacterUid.substr(3,1);
sPos5 = sCharacterUid.substr(0,1);
sPos6 = sCharacterUid.substr(1,1);
sCharacterUid = sPos1 + sPos2 + " " + sPos3 + sPos4 + " " + sPos5 + sPos6;
String^ sfCharacterUid = gcnew String(sCharacterUid.c_str());
but I am wondering how I can cut down the amount of code needed to perform this task.
This is in c++/cli.
Thanks.
at first glance, why not
sPos1 = sCharacterUid.substr(4,2);
sPos3 = sCharacterUid.substr(2,2);
sPos5 = sCharacterUid.substr(0,2);
sCharacterUid = sPos1 + " " + sPos3 + " " + sPos5;
Or
string result="";
for (i=4;i>=0;i-=2)
result += sCharacterUid.substr(i,2) + " ";
Or, it may be more efficient to work with raw chars.
char result=[9];
char* dest=result;
char* source = sCharacterUid.c_str();
for (i=4;i>=0;i-=2)
{
*dest++ = source[i];
*dest++ = source[i+1];
*dest++ = ' ';
}
*(--dest)='\0';
String^ sfCharacterUid = gcnew String(result);
std::string & S = sCharacterUid;
S = S.substr (4, 2) + " " + S.substr (2, 2) + " " + S.substr (0, 2);
I made some attempts to implement an efficient of rc4 cipher algorithm in cuda. I used shared memory to store the internal permutation state, taking care of the banked memory layout to time penalty with parallel thread accesses in the warp. I also tried to minimize the number of accesses exploiting the fact that read/write accesses with the 'i' index are contiguous and can be packed in 32-bits words. Last, I made use of constant memory to initialize the permutation state.
Despite these 'clever' tricks, i can expect to achieve only roughly 50% of throughput of the best reported implementations (see guapdf cracker for example), even taking into consideration that unblocked communication between host and gpu could be used to partially cover the computation. I can't figure why and I am looking for new improvement ideas or comments on bad assumptions i could have made.
Here is a toy implementation of my KSA (key setting) kernel with a key reduced to 4 bytes.
__constant__ unsigned int c_init[256*32/4];
__global__ void rc4Block(unsigned int *d_out, unsigned int *d_in)
{
__shared__ unsigned int s_data[256*32/4];
int inOffset = blockDim.x * blockIdx.x;
int in = inOffset + threadIdx.x;
unsigned int key, u;
// initialization
key = d_in[in];
for(int i=0; i<(256/4); i++) { // read from constant memory
s_data[i*32+threadIdx.x] = c_init[i*32+threadIdx.x];
}
// key mixing
unsigned char j = 0;
unsigned char k0 = key & 0xFF;
unsigned char k1 = (key >> 8) & 0xFF;
unsigned char k2 = (key >> 8) & 0xFF;
unsigned char k3 = (key >> 8) & 0xFF;
for(int i=0; i<256; i+=4) { // unrolled
unsigned int u, sj, v;
unsigned int si = s_data[(i/4)*32+threadIdx.x];
unsigned int shiftj;
u = si & 0xff;
j = (j + k0 + u) & 0xFF;
sj = s_data[(j/4)*32+threadIdx.x];
shiftj = 8*(j%4);
v = (sj >> shiftj) & 0xff;
si = (si & 0xffffff00) | v;
sj = (sj & ~(0xFFu << (8*(j%4)))) | (u << shiftj);
s_data[(j/4)*32+threadIdx.x] = sj;
u = (si >> 8) & 0xff;
j = (j + k1 + u) & 0xFF;
sj = s_data[(j/4)*32+threadIdx.x];
shiftj = 8*(j%4);
v = (sj >> shiftj) & 0xff;
si = (si & 0xffff00ff) | (v<<8);
sj = (sj & ~(0xFFu << (8*(j%4)))) | (u << shiftj);
s_data[(j/4)*32+threadIdx.x] = sj;
u = (si >> 16) & 0xff;
j = (j + k2 +u) & 0xFF;
sj = s_data[(j/4)*32+threadIdx.x];
shiftj = 8*(j%4);
v = (sj >> shiftj) & 0xff;
si = (si & 0xff00ffff) | (v<<16);
sj = (sj & ~(0xFFu << (8*(j%4)))) | (u << shiftj);
s_data[(j/4)*32+threadIdx.x] = sj;
u = (si >> 24) & 0xff;
j = (j + k3 + u) & 0xFF;
sj = s_data[(j/4)*32+threadIdx.x];
shiftj = 8*(j%4);
v = (sj >> shiftj) & 0xff;
si = (si & 0xffffff) | (v<<24);
sj = (sj & ~(0xFFu << (8*(j%4)))) | (u << shiftj);
s_data[(j/4)*32+threadIdx.x] = sj;
s_data[(i/4)*32+threadIdx.x] = si;
}
d_out[in] = s_data[threadIdx.x]; // unrelevant debug output
}
It seems the code at least partially involves re-ordering bytes. If you are using a Fermi-class GPU, you could look into using the __byte_perm() intrinsic which maps to a hardware instruction on Fermi-class devices and allows one to re-order bytes more efficiently.
I assume when you compare to other implementations it is apples-to-apples, i.e. on the same type of GPU. This code looks entirely compute bound, so the throughput will largely depend on the integer-instruction throughput of the GPU, and the performance spectrum is wide.