Re: Can't recreate a range?

2020-04-30 Thread Casey via Digitalmars-d-learn

On Thursday, 30 April 2020 at 18:30:14 UTC, H. S. Teoh wrote:
On Thu, Apr 30, 2020 at 06:05:55PM +, Paul Backus via 
Digitalmars-d-learn wrote: [...]
Doing work in popFront instead of front is usually an 
anti-pattern, since it forces eager evaluation of the next 
element even when that element is never used. You should only 
do this if there's no reasonable way to avoid it.


Really?? IME, usually you *need* to do work in popFront instead 
of front, because otherwise .empty wouldn't be able to tell 
whether there is another element or not.  E.g., in filtering a 
range based on some criterion on each element, you can't defer 
computing the next element until .front because you can't 
predict whether there will be another element that won't be 
dropped by popFront.


Also, for ranges based on generator functions, if .front is 
lazy then you need to keep extra baggage around your range to 
indicate whether or not the generator has been invoked yet; 
it's easier to just always compute the next element eagerly and 
cache it, and .front just returns the cached data.


Even when the range involves some expensive per-element 
computation, I find that it's simpler to just compute and cache 
in .popFront instead of adding extra baggage to .front to know 
when the computation has already been performed.


I'm hard-pressed to come up with an example where deferring 
computation to .front is a good idea!



T


Well, I just remembered that I had a tab open to this: 
http://ddili.org/ders/d.en/ranges.html


Reading, you see the following:

* empty: specifies whether the range is empty; it must return 
true when the range is considered to be empty, and false otherwise
* front: provides access to the element at the beginning of the 
range
* popFront(): shortens the range from the beginning by removing 
the first element


Looking at that, if popFront shortens the range, then to me it 
sounds like the work should be done in popFront.


Re: Can't recreate a range?

2020-04-30 Thread Casey via Digitalmars-d-learn
On Thursday, 30 April 2020 at 16:21:05 UTC, Steven Schveighoffer 
wrote:
I would say part of the issue is that you are doing all your 
work in front and not popFront.


What happens is that Appender is a pointer-to-implementation 
struct, and the compiler will allocate the first one shared 
amongst all initial StreamRange instances.


On your first call to front, it's going to utilize that shared 
one. Then on the call to popFront, it will reset it to another 
one.


For the second unittest, in your first call to front, it 
notices that it's already been filled, so it doesn't do any 
work (and returns the existing buffer).


Interesting.  I'll take this into account.  I was putting the 
work into front because I didn't want to do the work until it was 
requested.  Putting the work in popFront makes more sense in some 
ways, but the fact you have to call it before getting any records 
seems like it would break normal range algorithms.  (Please 
correct me if I'm wrong)  I'm wondering if putting the work into 
it's own method and calling it one from the constructor and from 
popFront the rest of the way.


another problem, your empty condition is based on the input, 
which violates range expectations. indeed, on the first call to 
front, the range all of a sudden becomes empty.


I was about to argue the point, but after thinking about the use 
of popFront to execute the work, that would work.


3. You don't need a further Range parameter for the nested 
struct, it can use the template parameter from the containing 
function.
4. Make it a static struct, or else it will retain a pointer to 
the function stack frame needlessly.


I'll definitely try that out.  Regarding 3, I think that was in 
the example code I used, so I just went with it.




Re: Can't recreate a range?

2020-04-30 Thread Casey via Digitalmars-d-learn

On Thursday, 30 April 2020 at 15:42:03 UTC, Casey wrote:
I'll give it a try when I get back to it (fixing lint issues), 
but are you sure that's the issue?  In popFront, I recreate the 
appender.  So, the appender should be clear before the empty 
check after it processes the last of the data from _input.  
Still a good thing to do as a best practice; I'm just wondering 
if something else is causing an issue and even if initializing 
the appender in the constructor solves the problem, I'd be 
suspect of future issues cropping up.


O.K.  It's working now, but I suspect there may still be 
something else going on.  The more I think of it, the more I 
suspect there's a newline at the end of the file that isn't 
accounted for until after the last tag is read from the file, so 
the input is not empty, so my code's empty check fails.


Regardless, thanks for the help!


Re: Can't recreate a range?

2020-04-30 Thread Casey via Digitalmars-d-learn

On Thursday, 30 April 2020 at 13:23:25 UTC, Paul Backus wrote:
Using a default value like this means that it will be shared 
among all instances of the struct. Instead, you should set 
`buff = appender!string` in the constructor, so that each 
struct will have its own appender.


I'll give it a try when I get back to it (fixing lint issues), 
but are you sure that's the issue?  In popFront, I recreate the 
appender.  So, the appender should be clear before the empty 
check after it processes the last of the data from _input.  Still 
a good thing to do as a best practice; I'm just wondering if 
something else is causing an issue and even if initializing the 
appender in the constructor solves the problem, I'd be suspect of 
future issues cropping up.


Re: Can't recreate a range?

2020-04-30 Thread Casey via Digitalmars-d-learn

On Wednesday, 29 April 2020 at 22:32:00 UTC, Simen Kjærås wrote:
I mean, it might be you messed up in posting this, but having 
an empty popFront and expecting it to do something is a tad 
optimistic.


I was just trying to get the example to a very minimal state.  I 
just added more descriptive code that replicates the bug.




What's the value of count when the code asserts?


The count ends up being the count of the previous test + the 
count of the current test.  In the code I uploaded, the first 
test will get 1, but the second test will get 2.  I'm printing 
out the output of the range to force it to actually perform the 
loop, so you can see that the contents of the first file are 
printed twice.


Re: Can't recreate a range?

2020-04-30 Thread Casey via Digitalmars-d-learn

Here's a minimal code example that duplicates the issue:

import std.array, std.range, std.stdio, std.traits, std.string;

auto readStream(Range)(auto ref Range r) if 
(isInputRange!(Unqual!Range))

{
struct StreamRange(Range)
{
alias R = Unqual!Range;
R _input;

auto buff = appender!string;

this(R input)
{
this._input = input;
}

bool empty()
{
return this._input.empty;
}

string front()
{
if (buff.capacity == 0)
{
bool iterate = true;
bool doCapture = false;
buff.reserve(1000);

while (iterate)
{
if (this._input.empty)
break;

auto value = this._input.front;
if (value.strip == "")
{
doCapture = true;
buff.put(value.strip);
buff.put("\n");
}
else if (value.strip == "")
{
buff.put(value.strip);
doCapture = false;
iterate = false;
}
else if (doCapture)
{
buff.put(value.strip);
buff.put("\n");
}
this._input.popFront();
}
}
return buff[];
}

void popFront()
{
buff = appender!string;
}
}

return StreamRange!(Range)(r);
}

unittest
{
auto range = readStream(File("test1.xml").byLine);
int count = 0;
while (!range.empty)
{
writeln(range.front);
count++;
writeln("Current count: ", count);
range.popFront();
}
assert(count == 1);
}

unittest
{
auto range = readStream(File("test2.xml").byLine);
int count = 0;
while (!range.empty)
{
writeln(range.front);
count++;
writeln("Current count: ", count);
range.popFront();
}
assert(count == 1);
}


Here are the two XML files (very simple):



Here is some text for the first file.




Here is some text for the second file.


I've even tried putting wrapping the code that is being tested in 
a function and looping over it with different parameters 
(filename and expected count) without any luck either.  I've also 
tried declaring the file handle separate and ensuring it was 
closed.  No luck.


Can't recreate a range?

2020-04-29 Thread Casey via Digitalmars-d-learn
So, I'm trying to run some tests and I had code that looks 
similar to this:


unittest
{
auto range = 
readStream(File("test_data/multiple.xml").byLine);

int count = 0;
while (!range.empty)
{
count++;
range.popFront();
}
assert(count == 3);
}

However, if I have a second block above/below it doing the same 
thing, the last assert will fail because in the second block it 
appears the ranges have been joined together.  E.g.:


unittest
{
auto range = 
readStream(File("test_data/multiple.xml").byLine);

int count = 0;
while (!range.empty)
{
count++;
range.popFront();
}
assert(count == 3); // Passes
}

unittest
{
auto range = 
readStream(File("test_data/another.xml").byLine);

int count = 0;
while (!range.empty)
{
count++;
range.popFront();
}
assert(count == 2); // Fails
}

To me, it looks like range is not  being overwritten.  The code 
for readStream looks similar to this:


auto readStream(Range)(auto ref Range r) if 
(isInputRange!(Unqual!Range))

{
struct StreamRange(Range)
{
alias R = Unqual!Range;
R _input;

this(R input)
{
this._input = input;
}

bool empty()
{
return this._input.empty;
}

string front()
{
// Do stuff...
}

void popFront()
{
}
}

return StreamRange!(Range)(r);
}

I feel like I'm missing something obscure and it's driving me a 
bit batty.  Any clue as to why this is happening?  I'd like to 
not have to worry about creating new variable names between 
tests.  To me, it seems like each unittest block is independent 
of each other and I haven't come across anything that contradicts 
that.  However, I didn't find anything that confirms it either.


Thanks.


Re: Dub and unit-threaded import problem

2016-03-05 Thread Casey via Digitalmars-d-learn

On Saturday, 5 March 2016 at 18:01:48 UTC, Atila Neves wrote:

On Saturday, 5 March 2016 at 15:05:50 UTC, Casey wrote:

Hello,

I'm just starting a small project with dub and unit-threaded, 
but I'm getting an issue where the file "unit_threaded.d" 
cannot be found.


[...]


You mispelled "dependencies".

Atila


Oh, and forgot to mention I like what you did with this new 
update of unit-threaded.  Can't wait to get some code written.


Re: Dub and unit-threaded import problem

2016-03-05 Thread Casey via Digitalmars-d-learn

On Saturday, 5 March 2016 at 18:01:48 UTC, Atila Neves wrote:

On Saturday, 5 March 2016 at 15:05:50 UTC, Casey wrote:

Hello,

I'm just starting a small project with dub and unit-threaded, 
but I'm getting an issue where the file "unit_threaded.d" 
cannot be found.


[...]


You mispelled "dependencies".

Atila


Thanks.  I knew it had to be something dumb.


Dub and unit-threaded import problem

2016-03-05 Thread Casey via Digitalmars-d-learn

Hello,

I'm just starting a small project with dub and unit-threaded, but 
I'm getting an issue where the file "unit_threaded.d" cannot be 
found.


Details:

DMD version: DMD64 2.070.0

Dub version: 0.9.24

Dub Config:

{
"name": "pst",
"targetType": "executable",
"targetPath": "bin",
"configurations": [
{
"name": "unittest",
"preBuildCommands": [
"dub run unit-threaded -c gen_ut_main -- -f 
bin/ut.d"

],
"mainSourceFile": "bin/ut.d",
"excludedSourceFiles": ["source/app.d"],
"dependences": {
"unit-threaded": "~>0.6.3"
}
}
]
}

I haven't created any tests at this time.  It's a bare project.  
I just wanted to make sure the dub config worked before I started 
coding.  I feel I'm missing something very simple.  I just don't 
see it.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn
On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
wrote:
On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki Cattermole 
wrote:
I did find this [0]. I don't know what state its in for 
compilating/running ext. But it might give you a good starting 
point.


[0] https://github.com/pythoneer/XInputSimulator


ooh there's some nice code for Linux in there! The Windows is 
only half implemented though... but this combined with my 
Windows code should get you enough example to write a 
cross-platform thing if you need it.


Thank you so much!  I really appreciate this!  But I have a few 
questions.


1) Which compiler should I use?  I'm attempting to use the DM D 
comiler, but afaik it doesn't have a GUI and I can't make any 
sense of how to use it otherwise.  I'll look up a tutorial on it 
if this is the one you recommend.  If it's not the one you 
recommend, I'll give yours a try.


2) I can't figure out what the heck half of this code means.  It 
seems that at the bottom you have what each of the hotkey buttons 
are, and I can see a few times where you referenced them.  I can 
also see a efw listeners for the keybinds to be pressed, and then 
where you use the writeln command.  Other than that, I can't tell 
what's going on.  I feel like a noob, sorry that I don't 
understand this.


3) I'm sure that everything you have in there has a meaning, but 
it looks over complicated to me.  Shouldn't it look something 
like this?


[code]
void main() {
import std.stdio;
import simpledisplay;
import *Others that need to be imported*;
if (*hotkey command here*) {
then writeln (We're losing Alpha!)
return 0;
}
[/code]

I know there's a /LOT/ more to it than that, but wouldn't that be 
the basics?  I honestly don't know a whole lot about what you 
did, but at least I understand the basic concept of programming.


I'm going to start looking up a few tutorials on compiling using 
the DM D compiler, let me know if you recommend a different one.


Could you tell me which keys you used for the hotkey in your 
sample code?  I can't figure it out, but my guess it alt + c?  
Not sure though.


Thanks again, I am really impressed with you for actually writing 
the basic concept of it for me!  I can diffidently use this for 
my building block of learning how to program better!


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn

On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
wrote:
On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki 
Cattermole wrote:
I did find this [0]. I don't know what state its in for 
compilating/running ext. But it might give you a good 
starting point.


[0] https://github.com/pythoneer/XInputSimulator


ooh there's some nice code for Linux in there! The Windows is 
only half implemented though... but this combined with my 
Windows code should get you enough example to write a 
cross-platform thing if you need it.


Thank you so much!  I really appreciate this!  But I have a few 
questions.


1) Which compiler should I use?  I'm attempting to use the DM D 
comiler, but afaik it doesn't have a GUI and I can't make any 
sense of how to use it otherwise.  I'll look up a tutorial on 
it if this is the one you recommend.  If it's not the one you 
recommend, I'll give yours a try.


2) I can't figure out what the heck half of this code means.  
It seems that at the bottom you have what each of the hotkey 
buttons are, and I can see a few times where you referenced 
them.  I can also see a efw listeners for the keybinds to be 
pressed, and then where you use the writeln command.  Other 
than that, I can't tell what's going on.  I feel like a noob, 
sorry that I don't understand this.


3) I'm sure that everything you have in there has a meaning, 
but it looks over complicated to me.  Shouldn't it look 
something like this?


[code]
void main() {
import std.stdio;
import simpledisplay;
import *Others that need to be imported*;
if (*hotkey command here*) {
then writeln (We're losing Alpha!)
return 0;
}
[/code]

I know there's a /LOT/ more to it than that, but wouldn't that 
be the basics?  I honestly don't know a whole lot about what 
you did, but at least I understand the basic concept of 
programming.


I'm going to start looking up a few tutorials on compiling 
using the DM D compiler, let me know if you recommend a 
different one.


Could you tell me which keys you used for the hotkey in your 
sample code?  I can't figure it out, but my guess it alt + c?  
Not sure though.


Thanks again, I am really impressed with you for actually 
writing the basic concept of it for me!  I can diffidently use 
this for my building block of learning how to program better!



Ok so I've found out how to compile using the DM D compiler via 
terminal...  I can't cd to my directory for whatever reason... so 
I'm running this:


[code]
dmd D:\Documents\Other\Hotkeys\D\Keybinds.d
[/code]
But it's spitting out errors left and right.  Here's what I get:


[code]
C:\Users\Caseydmd D:\Documents\Other\Hotkeys\D\Keybinds.d
D:\Documents\Other\Hotkeys\D\Keybinds.d(11): Error: undefined 
identifier KEYEVEN

TF_UNICODE
D:\Documents\Other\Hotkeys\D\Keybinds.d(25): Error: module 
simpledisplay is in f

ile 'simpledisplay.d' which cannot be read
import path[0] = D:\Program Files (x86)\DM D Programming Language 
Compiler\D\dmd

2\windows\bin\..\..\src\phobos
import path[1] = D:\Program Files (x86)\DM D Programming Language 
Compiler\D\dmd

2\windows\bin\..\..\src\druntime\import

[/code]

It's basically telling me I need the two files you mentioned that 
are on your Github.  So I then went and got your two files, 
copied their stuff into their own folders, and tried to compile 
them.  Here's what I got:


[code]
C:\Users\Caseydmd D:\Documents\Other\Hotkeys\D\simpledisplay.d
D:\Documents\Other\Hotkeys\D\simpledisplay.d(274): Error: module 
color is in fil

e 'arsd\color.d' which cannot be read
import path[0] = D:\Program Files (x86)\DM D Programming Language 
Compiler\D\dmd

2\windows\bin\..\..\src\phobos
import path[1] = D:\Program Files (x86)\DM D Programming Language 
Compiler\D\dmd

2\windows\bin\..\..\src\druntime\import


C:\Users\Caseydmd D:\Documents\Other\Hotkeys\D\color.d
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 23: No Stack
color.obj(color)
 Error 42: Symbol Undefined __fltused
color.obj(color)
 Error 42: Symbol Undefined __d_arraybounds
color.obj(color)
 Error 42: Symbol Undefined __memset80
color.obj(color)
 Error 42: Symbol Undefined __d_assert
color.obj(color)
 Error 42: Symbol Undefined __d_arraycatT
color.obj(color)
 Error 42: Symbol Undefined __d_throwc
color.obj(color)
 Error 42: Symbol Undefined 
_D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9Th

rowableZC9Exception
color.obj(color)
 Error 42: Symbol Undefined __d_newclass
color.obj(color)
 Error 42: Symbol Undefined _D9Exception7__ClassZ
color.obj(color)
 Error 42: Symbol Undefined _D12TypeInfo_Aya6__initZ
color.obj(color)
 Error 42: Symbol Undefined __d_arrayappendcTX
color.obj(color)
 Error 42: Symbol Undefined _D14TypeInfo_Array6__vtblZ
color.obj(color)
 Error 42: Symbol Undefined __d_assert_msg
color.obj(color)
 Error 42: Symbol Undefined 

Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn
I also just now got it to CD to the right directory.  I had a 
suspicion it was having an issue with the second drive, and it 
was.  Just had to type D: and it did the rest.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn

On Thursday, 13 November 2014 at 22:28:43 UTC, Israel wrote:

On Thursday, 13 November 2014 at 22:20:58 UTC, Casey wrote:

On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
wrote:
On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki 
Cattermole wrote:
I did find this [0]. I don't know what state its in for 
compilating/running ext. But it might give you a good 
starting point.


[0] https://github.com/pythoneer/XInputSimulator


ooh there's some nice code for Linux in there! The Windows 
is only half implemented though... but this combined with my 
Windows code should get you enough example to write a 
cross-platform thing if you need it.


Thank you so much!  I really appreciate this!  But I have a 
few questions.


1) Which compiler should I use?  I'm attempting to use the DM 
D comiler, but afaik it doesn't have a GUI and I can't make 
any sense of how to use it otherwise.  I'll look up a 
tutorial on it if this is the one you recommend.  If it's not 
the one you recommend, I'll give yours a try.


2) I can't figure out what the heck half of this code means.  
It seems that at the bottom you have what each of the hotkey 
buttons are, and I can see a few times where you referenced 
them.  I can also see a efw listeners for the keybinds to be 
pressed, and then where you use the writeln command.  Other 
than that, I can't tell what's going on.  I feel like a noob, 
sorry that I don't understand this.


3) I'm sure that everything you have in there has a meaning, 
but it looks over complicated to me.  Shouldn't it look 
something like this?


[code]
void main() {
  import std.stdio;
  import simpledisplay;
  import *Others that need to be imported*;
  if (*hotkey command here*) {
  then writeln (We're losing Alpha!)
  return 0;
}
[/code]

I know there's a /LOT/ more to it than that, but wouldn't 
that be the basics?  I honestly don't know a whole lot about 
what you did, but at least I understand the basic concept of 
programming.


I'm going to start looking up a few tutorials on compiling 
using the DM D compiler, let me know if you recommend a 
different one.


Could you tell me which keys you used for the hotkey in your 
sample code?  I can't figure it out, but my guess it alt + c?

 Not sure though.

Thanks again, I am really impressed with you for actually 
writing the basic concept of it for me!  I can diffidently 
use this for my building block of learning how to program 
better!



Ok so I've found out how to compile using the DM D compiler 
via terminal...  I can't cd to my directory for whatever 
reason... so I'm running this:


[code]
dmd D:\Documents\Other\Hotkeys\D\Keybinds.d
[/code]
But it's spitting out errors left and right.  Here's what I 
get:



[code]
C:\Users\Caseydmd D:\Documents\Other\Hotkeys\D\Keybinds.d
D:\Documents\Other\Hotkeys\D\Keybinds.d(11): Error: undefined 
identifier KEYEVEN

TF_UNICODE
D:\Documents\Other\Hotkeys\D\Keybinds.d(25): Error: module 
simpledisplay is in f

ile 'simpledisplay.d' which cannot be read
import path[0] = D:\Program Files (x86)\DM D Programming 
Language Compiler\D\dmd

2\windows\bin\..\..\src\phobos
import path[1] = D:\Program Files (x86)\DM D Programming 
Language Compiler\D\dmd

2\windows\bin\..\..\src\druntime\import

[/code]

It's basically telling me I need the two files you mentioned 
that are on your Github.  So I then went and got your two 
files, copied their stuff into their own folders, and tried to 
compile them.  Here's what I got:


[code]
C:\Users\Caseydmd D:\Documents\Other\Hotkeys\D\simpledisplay.d
D:\Documents\Other\Hotkeys\D\simpledisplay.d(274): Error: 
module color is in fil

e 'arsd\color.d' which cannot be read
import path[0] = D:\Program Files (x86)\DM D Programming 
Language Compiler\D\dmd

2\windows\bin\..\..\src\phobos
import path[1] = D:\Program Files (x86)\DM D Programming 
Language Compiler\D\dmd

2\windows\bin\..\..\src\druntime\import


C:\Users\Caseydmd D:\Documents\Other\Hotkeys\D\color.d
OPTLINK (R) for Win32  Release 8.00.15
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Warning 23: No Stack
color.obj(color)
Error 42: Symbol Undefined __fltused
color.obj(color)
Error 42: Symbol Undefined __d_arraybounds
color.obj(color)
Error 42: Symbol Undefined __memset80
color.obj(color)
Error 42: Symbol Undefined __d_assert
color.obj(color)
Error 42: Symbol Undefined __d_arraycatT
color.obj(color)
Error 42: Symbol Undefined __d_throwc
color.obj(color)
Error 42: Symbol Undefined 
_D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9Th

rowableZC9Exception
color.obj(color)
Error 42: Symbol Undefined __d_newclass
color.obj(color)
Error 42: Symbol Undefined _D9Exception7__ClassZ
color.obj(color)
Error 42: Symbol Undefined _D12TypeInfo_Aya6__initZ
color.obj(color)
Error 42: Symbol Undefined __d_arrayappendcTX
color.obj(color)
Error 42: Symbol Undefined _D14TypeInfo_Array6__vtblZ
color.obj(color)

Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn
All on the same line... That makes a lot more sense.  Sorry, I 
probably just didn't understand what you meant.  I'll do that now 
and see if I can't get this working.  Then I'll try to get it 
working in a game.  I think I'll have to come up with something 
to add a delay in between the chat key down and chat key up, as 
without that, it didn't work with AHK.


I have this error now:

D:\Documents\Other\Hotkeys\Ddmd Keybinds.d simpledisplay.d 
color.d

Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE

Not sure what to do at this point.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn

On Thursday, 13 November 2014 at 23:54:13 UTC, Casey wrote:
All on the same line... That makes a lot more sense.  Sorry, I 
probably just didn't understand what you meant.  I'll do that 
now and see if I can't get this working.  Then I'll try to get 
it working in a game.  I think I'll have to come up with 
something to add a delay in between the chat key down and chat 
key up, as without that, it didn't work with AHK.


I have this error now:

D:\Documents\Other\Hotkeys\Ddmd Keybinds.d simpledisplay.d 
color.d

Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE

Not sure what to do at this point.


Now I feel like a real idiot.  It's telling me there's an error 
on line 11 if I'm not mistaken.  I'm going to see if I edited 
your code by mistake and report back here.


Yep, it didn't give an error this time around.  However when I 
run the .exe I get your popup window and a blank terminal.  
Pressing all the F keys does nothing.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn

On Thursday, 13 November 2014 at 23:59:59 UTC, Casey wrote:

On Thursday, 13 November 2014 at 23:54:13 UTC, Casey wrote:
All on the same line... That makes a lot more sense.  Sorry, I 
probably just didn't understand what you meant.  I'll do that 
now and see if I can't get this working.  Then I'll try to get 
it working in a game.  I think I'll have to come up with 
something to add a delay in between the chat key down and chat 
key up, as without that, it didn't work with AHK.


I have this error now:

D:\Documents\Other\Hotkeys\Ddmd Keybinds.d simpledisplay.d 
color.d

Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE

Not sure what to do at this point.


Now I feel like a real idiot.  It's telling me there's an error 
on line 11 if I'm not mistaken.  I'm going to see if I edited 
your code by mistake and report back here.


Yep, it didn't give an error this time around.  However when I 
run the .exe I get your popup window and a blank terminal.  
Pressing all the F keys does nothing.


Nevermind, working now.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn
Well, I edited the code to add the chat button, and as I feared 
it didn't recignise it in game.  However, if I manually press the 
chat button it'll work fine, so all I need to do is add that 
delay in, then fine tune it to add all of the different messages 
I need now.


1)What part of this do I need to keep when adding the second 
hotkey?  Include an example if possible.  I find it hard to 
understand what is necessary to repeat and what I can just 
include once.


2)All I need to do at the moment to enable this to work is to add 
a ~1ms delay from the time the chat key is pressed down, and when 
it is pressed up.  Then it /should/ funtion in game properly.


3)It's a personal preference of mine to not have the chat window 
pop up like it does, nor the terminal popup.  This is a minor 
request, so I don't need it immediately.  Is there any way to 
make those disappear?


4)I'd like the first hotkey to be 0 + 1 on the numpad.  Numlock 
is always enabled on my keyboard, so I can't use arrows or 
anything like that.  The second set of hotkeys would be Ctrl + 
Del/End/PgDn/Insert/Home/PgUp, each one sending a different 
message.


5)Is there any way to pause the commands?  I have one hotkey set 
to Ctrl + Delete, and it gets really annoying when I try to 
Delete a full word but instead I send a chat message.  I think 
that I could activate and pause it with another hotkey, something 
like ctrl + numpad 0.  That should be something I'd never press.


I'm going to see if I can't figure everything above out on my 
own.  Maybe I'll start to learn it a bit more.  I'm also assuming 
I'll need another package to be imported if I am to add that 
delay, but it might already be in one of these.


Thanks so much everyone for your help.  It really means a lot to 
me.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn

Aha!  I found a sleep command.

On this page here:

http://forum.dlang.org/thread/diuepu$2ebg$1...@digitaldaemon.com

Looks like I'd do something like this

[code]
import std.c.time
msleep(1)
[/code]

Now I'm looking into if there's a way to send a key down, and 
then up.  I don't think this will be too easy to find though.


Re: Basically want to make a macro script

2014-11-13 Thread Casey via Digitalmars-d-learn

On Friday, 14 November 2014 at 03:51:17 UTC, Adam D. Ruppe wrote:

On Friday, 14 November 2014 at 02:08:22 UTC, Casey wrote:
Well, I edited the code to add the chat button, and as I 
feared it didn't recignise it in game.  However, if I manually 
press the chat button it'll work fine


What exactly happened there?

1)What part of this do I need to keep when adding the second 
hotkey?  Include an example if possible.  I find it hard to 
understand what is necessary to repeat and what I can just 
include once.


The RegisterHotKey function will need to be called again with a 
new ID. Then, the WM_HOTKEY message will have to handle the 
other hotkey id too.


You can copy and paste every instance of hotkey_id to make a 
hotkey2_id in a pinch.


I know there's a lot of concepts behind the MSDN pages that 
aren't all newbie friendly (well, actually, there are pages on 
it to explain the concepts too, in the References part at the 
bottom of each page. You'll be in for many hours of reading 
though, it took me weeks to get going beyond copy/paste and it 
was /years/ before I knew all the concepts, but gotta start 
somewhere). Anyway, take a look at the pages to better 
understand what the code is doing - the concepts will make 
sense too once you see enough of it and in the mean time, it 
can help to explain the pieces in isolation.


http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646279%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms646271%28v=vs.85%29.aspx

This is all Windows specific, of course, but the concepts apply 
to a lot of systems - if you can write Win32 code, you can do a 
lot of stuff.


2)All I need to do at the moment to enable this to work is to 
add a ~1ms delay from the time the chat key is pressed down, 
and when it is pressed up.  Then it /should/ funtion in game 
properly.


The easiest way would be to split up the part that does 
SendInput into two parts - notice how in the code, there were 
separate events for pressed and released. You'd need to split 
that up into two separate calls to SendInput with some kind of 
sleep in between. There's also a timestamp thing mentioned in 
the MSDN docs which might work but I'm not sure that would 
actually work.


3)It's a personal preference of mine to not have the chat 
window pop up like it does, nor the terminal popup.  This is a 
minor request, so I don't need it immediately.  Is there any 
way to make those disappear?


The terminal won't appear if you use the -L SUBSYSTEM thing 
from a previous post on the compile command at the end of the 
lit of files.


The window itself could be hidden with the ShowWindow system 
function, but then you'd have to consider: how will you close 
the program when you don't want the hotkeys registered anymore? 
Having a visible window makes that easy.


http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548%28v=vs.85%29.aspx

The hwnd ShowWindow needs is available through 
window.impl.hwnd, so like


ShowWindow(window.impl.hwnd, SW_HIDE);

i should add this to simpledisplay.d too...

4)I'd like the first hotkey to be 0 + 1 on the numpad.  
Numlock is always enabled on my keyboard, so I can't use 
arrows or anything like that.  The second set of hotkeys would 
be Ctrl + Del/End/PgDn/Insert/Home/PgUp, each one sending a 
different message.


The Virtual Keys thing is the answer here. Search for virtual 
key codes on MSDN and you'll find this


http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx

Then search that page for Numeric keypad 0 key and you'll 
find the VK_NUMPAD0 name and number.


5)Is there any way to pause the commands?  I have one hotkey 
set to Ctrl + Delete, and it gets really annoying when I try 
to Delete a full word but instead I send a chat message.  I 
think that I could activate and pause it with another hotkey, 
something like ctrl + numpad 0.  That should be something I'd 
never press.



This is pretty straightforward: you can use an if clause with a 
variable in the WM_HOTKEY message to skip processing. Or, you 
could use UnregisterHotKey, passing the hwnd from the window 
and the ID number to turn it off entirely, then RegisterHotKey 
again later to turn it back on.


I'm going to see if I can't figure everything above out on my 
own.  Maybe I'll start to learn it a bit more.  I'm also 
assuming I'll need another package to be imported if I am to 
add that delay, but it might already be in one of these.


core.thread is one you can import, that gives you Thread.sleep
http://dlang.org/phobos/core_thread.html#sleep

This isn't the way you'd do this in a real program - it is 
usually a bad idea to sleep the thread responsible for handling 
window messages because then it can become unresponsive, but as 
long as you only sleep for a few milliseconds at a time it 
shouldn't 

Re: Basically want to make a macro script

2014-11-12 Thread Casey via Digitalmars-d-learn
On Wednesday, 12 November 2014 at 08:02:06 UTC, ketmar via 
Digitalmars-d-learn wrote:

On Wed, 12 Nov 2014 04:56:39 +
Casey via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com wrote:


D has nothing to do with your task, WinAPI does. and you'll 
need alot
of expirience in reverse engineering, 'cause f... punkbuster 
shits it's
pants almost for anything. it's a rootkit, and very badly 
written one.
what you have to do is to fight with rootkit, making it think 
that it
is still functional. so learn assembler, x86 archtecture, 
winapi,

windows driver development, nt kernel internals and so on.

and don't even dream that it will be portable.


I don't need to do this I'm pretty sure... I just need to write 
something that will send the chat messages as described in my 
first post.  I don't need to rootkit PunkBuster, it's not trying 
to ban programs that send chat messages  It's simply trying 
to ban macro programs like AutoHotKey.  AHK can be used to make 
no recoil scripts, so they added an option so that server owners 
can choose to kick those players /if they want to/.


Again, I'm writing a simple program to send chat messages at a 
lowish level once a hotkey/keybind has been pressed.  All it 
needs is to add a delay in between the chat key presses (Like 
*chat key* down, then 1 ms later, chat key up)(Forgot to mention 
that last night), typing my actual message as quickly as 
possible, then to send the message.


In other words, it needs to recignise my keybind, press the chat 
button down, then up with a small delay in between, send my 
message and press enter.


PB nor any other program should find this as a cheating program.  
It's not a cheat at all.  It's not a mod, hack, nor advantage 
that others can't do.  It's not unfair, it's not too good, it's 
just something simple that I'm trying to make work.  It doesn't 
need a GUI, it just needs what I've described above.  No 
rootkits, nothing like that afaik.  If it's not a hack/cheat, PB 
isn't going to look at it like it is one (hopefully).


Thank you for your interest and reply.


Re: Basically want to make a macro script

2014-11-12 Thread Casey via Digitalmars-d-learn

On Wednesday, 12 November 2014 at 19:29:26 UTC, Israel wrote:

On Wednesday, 12 November 2014 at 04:56:40 UTC, Casey wrote:

also, you came to the right place. PB is extremely paranoid and
even more so about autohokey, so if you program your own native
macro, its not very likely it will catch it.


I didn't see your replies at first... Thanks for your interest.

If D isn't the right language, I can go with something else like 
C++ or python.  It's just got to have something that can send low 
level chat messages, or emulate actual keyboard presses so that I 
won't have issues with other games.   (/NOT/ C# simply because 
Micro$oft makes it and I try to avoid their stuff as much as 
possible).


I chose D simply because I've heard it's got a lot of potential 
and it's somewhat similar to C++, yet easyish to learn.  I'm up 
for anything, but I figured that if I went with D or C++ I'd be 
jumping right into it, so that would give me the most experience. 
 I thought this shouldn't be too hard to make, but I just can't 
find anything that does the job 'm looking for.


Re: Basically want to make a macro script

2014-11-12 Thread Casey via Digitalmars-d-learn

On Wednesday, 12 November 2014 at 23:35:33 UTC, Israel wrote:

On Wednesday, 12 November 2014 at 19:43:49 UTC, Casey wrote:

On Wednesday, 12 November 2014 at 19:29:26 UTC, Israel wrote:

On Wednesday, 12 November 2014 at 04:56:40 UTC, Casey wrote:

also, you came to the right place. PB is extremely paranoid 
and
even more so about autohokey, so if you program your own 
native

macro, its not very likely it will catch it.


I didn't see your replies at first... Thanks for your interest.

If D isn't the right language, I can go with something else 
like C++ or python.  It's just got to have something that can 
send low level chat messages, or emulate actual keyboard 
presses so that I won't have issues with other games.   (/NOT/ 
C# simply because Micro$oft makes it and I try to avoid their 
stuff as much as possible).


I chose D simply because I've heard it's got a lot of 
potential and it's somewhat similar to C++, yet easyish to 
learn.  I'm up for anything, but I figured that if I went with 
D or C++ I'd be jumping right into it, so that would give me 
the most experience.
I thought this shouldn't be too hard to make, but I just can't 
find anything that does the job 'm looking for.


Its not that D isnt the right language its just that it isnt
yet.
There are few libraries that allow you to take control over the
mouse and keyboard without too much hassle and reading through
documentation.

I did find this a couple days ago.
http://code.dlang.org/packages/de_window
It might be what you need but im not entirely sure if its input
simulation is across all programs.


I'll look into that, it seems as it might work.  If D would be 
too hard to get working, what would you recommend?  I would 
assume Ptyhon or C++ would be good choices, any chance you can 
recommend a forum for these or something?  It's hard to find any 
documentation on what I am looking for.


Thanks.


Re: Basically want to make a macro script

2014-11-12 Thread Casey via Digitalmars-d-learn

On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:

On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:



I'll look into that, it seems as it might work.  If D would be 
too hard to get working, what would you recommend?  I would 
assume Ptyhon or C++ would be good choices, any chance you can 
recommend a forum for these or something?  It's hard to find 
any documentation on what I am looking for.


Thanks.


I tried to test out that de_window library but it doesnt work 
out

of the box.

The guy who created it though does post in this forum so maybe 
if

he magically finds this thread he can help you and me out.


That would be nice.  I'll see if there's a way to PM him about 
it.  Do you have any other programming language recommendations 
in case this doesn't work out?


Re: Basically want to make a macro script

2014-11-12 Thread Casey via Digitalmars-d-learn

On Thursday, 13 November 2014 at 02:58:02 UTC, Rikki Cattermole
wrote:

On 13/11/2014 3:45 p.m., Israel wrote:

On Thursday, 13 November 2014 at 02:00:11 UTC, Rikki Cattermole
wrote:

On 13/11/2014 2:37 p.m., Casey wrote:

On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:

On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:



I'll look into that, it seems as it might work.  If D 
would be too
hard to get working, what would you recommend?  I would 
assume Ptyhon
or C++ would be good choices, any chance you can recommend 
a forum
for these or something?  It's hard to find any 
documentation on what

I am looking for.

Thanks.


I tried to test out that de_window library but it doesnt 
work out

of the box.

The guy who created it though does post in this forum so 
maybe if

he magically finds this thread he can help you and me out.


That would be nice.  I'll see if there's a way to PM him 
about it.  Do
you have any other programming language recommendations in 
case this

doesn't work out?


Sorry that functionality of de_window is out of scope of it. 
So of
course, it won't work for what you want, it just creates a 
window and

a context cross platform with input for that window.

The functionality you are wanting is possible against winapi 
and x11
fairly easily. Its just low level. Although X11 is a little 
easier as

it can be done via a program on cli.
Unfortunately c/c++ will help you as much as D will in these 
cases.
If you run into trouble with those api's we can help you. But 
you will
need help, these are topics that aren't recommended for a 
newbie.


I'm not quite sure how to receive key presses from other 
windows.

Maybe Mike Parker (aldracon) has some ideas.


Do you have plans for making win32 bindings for the sendkeys?

Im interested in this too. Id like to do it with D but ive only
ever been able to accomplish this task with C# and 
InputSimulator.


At this point in time, I have no plans for such a library. 
However if somebody wishes to implement under the 
devisualization org, I'm happy to help.




It's great to have you two joining in on this thread!  I'm
excited to see how helpful you have all been, it's really
encouraging me to learn more about this.  Two of you guys have
noted that D and C++ might not be the right languages for my
purposes.  If they won't work for it, could you make some other
suggestions?  I'd really prefer to make it work in D, but if it's
not worth the trouble I'm more than happy to switch to something
simpler.  Thanks for your dedication all!


Basically want to make a macro script

2014-11-11 Thread Casey via Digitalmars-d-learn
/Long/ story short, I want to pretty much make a macro using this 
program.  I don't really have time to explain in further detail 
at the moment, but /no/ macro program out there will do what I'm 
trying to do.  I want to basically make it so that when I press a 
hotkey, it'll send an in game chat message.  Here's my code for 
the popular program AutoHotKey.


[code]
Numpad0  Numpad1::
Send {k down}
Sleep 1
Send {k up}
SendInput We're losing Alpha{!}
SendInput {Enter}
Return
[/code]

That's a small sample of my script, but the only thing that would 
change with the rest of my script would be the message sent and 
the keybind to press it.


Basically what it's doing is listening for my hotkey to be 
pressed (in this particular example it's numpad 0 + numpad 1 for 
the message, We're losing Alpha!, and so on and so forth for 
the rest of the numbers.)  and then activating the chat button in 
game (in this particular examle it's k for team chat), then 
sending the actual message as quickly as possible, and sending 
it.  Works perfectly in BF4, but PB (PunkBuster), the default 
anti cheat system that BF4 uses will kick me if the admins have 
that setting enabled.


I've been wanting to learn full on programming for a while, and 
I've heard a lot of things about D and how it's a pretty good 
starting point, and how it has a huge potential to expand you 
into anything.  Plus it's supposed to be pretty efficient and the 
next big thing in the programming world, so there's that.


Just for the record, I don't have a lot of experience with 
programming.  I've done it years ago (had an instructor for a Boy 
Scout Merit Badge class), but I didn't even know which language I 
was typing in.  I assume it was Python, but I can't be sure.  
Whatever I make I want it to be somewhat compatible with Linux 
eventually.  I just want to start with a binary .exe, but I do 
want my code to be compatible with Linux if I choose to compile 
it for Linux at a later date.  I don't think this should be an 
issue, but I just wanted to throw this out there.


I'm not sure which libraries I need for this, but as far as I 
know I just need the following:


Keybind listener/hotkey
Keyboard emulating/low level chat producing library
something that /wont/ be picked up as a hack/cheat by /ANYTHING/.

I don't think this should be that hard to make, but D doesn't 
really have much documentation out there as far as I can tell, so 
I figured this would be the best place to put this.


The sooner the better please.  Thanks for any/all help I receive.


Variable Naming Issue (Conflicts?)

2014-04-22 Thread Casey via Digitalmars-d-learn

Hello,

I'm working on some code where I'm trying to generate structs 
that map to JSON documents via a mixin.  That part works except 
when specific variable gets created.  Below is the error that I'm 
getting:


source/objects.d-mixin-70(75): Error: no identifier for 
declarator string
source/objects.d-mixin-70(75): Error: found '=' when 
expecting '('
source/objects.d-mixin-70(75): Error: basic type expected, 
not 
source/objects.d-mixin-70(75): Error: found '' when 
expecting ')'


If I prefix all of the generated variables with an underscore, it 
works fine.  It looks like the variable delete is the issue.  
To me, it looks like it's expecting some sort of delete method.


Now, I'm planning on leveraging vibe.d's JSON serialization to 
convert an object to/from JSON, so the variable names have to 
match the names they have in the JSON document.


My question is, is there a way I can prevent this conflict from 
occurring without affecting what the struct will look like?


Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread Casey via Digitalmars-d-learn

On Tuesday, 22 April 2014 at 19:38:09 UTC, bearophile wrote:

Casey:

My question is, is there a way I can prevent this conflict 
from occurring without affecting what the struct will look 
like?


The usual strategy is to append an underscore. (I think C# uses 
a @ prefix).


Bye,
bearophile


I've done that, but then it changes the name which, from what 
I've read in the documentation, means the JSON - object 
conversion won't work since it won't see a variable named delete.


Re: Variable Naming Issue (Conflicts?)

2014-04-22 Thread Casey via Digitalmars-d-learn
Perhaps we need a built-in syntax solution as in C#, like a 
$delete.


So, two things:

1. I guess my current approach is screwed.  I figured as much.
2. Seeing $delete makes me miss Perl/PHP variable naming.  It 
is one extra character, but it did make them stand out more.


Anyway, thanks.

Casey